我有一个简单的模板,用于客户端 Item
的打印列表和spring-boot . 但是当我尝试运行它然后得到错误:
错误5434 --- [nio-8080-exec-4] org.thymeleaf.TemplateEngine:[THYMELEAF] [http-nio-8080-exec-4]异常处理模板“get_all_items”:错误解析模板“get_all_items”,模板可能不存在或者可能无法通过任何已配置的模板解析器访问2017-08-22 19:37:31.302错误5434 --- [nio-8080-exec-4] oaccC [ . [ . [/] . [dispatcherServlet] ]:Servlet [dispatcherServlet]的Servlet.service()与path []的上下文引发异常[请求处理失败;嵌套异常是org.thymeleaf.exceptions.TemplateInputException:解析模板“get_all_items”时出错,模板可能不存在,或者任何已配置的模板解析器可能无法访问,但根本原因是org.thymeleaf.exceptions.TemplateInputException:解析模板时出错“ get_all_items“,模板可能不存在,或者任何已配置的模板都可能无法访问
这是我第一次使用百里香,请帮助我解决这个问题 . 谢谢 .
这是控制器:
@GetMapping("/get_all_items")
public ModelAndView getAllItems() {
final ModelAndView model = new ModelAndView();
final List<Item> all = service.getAll();
model.addObject("items", all);
return model;
}
这是MVC配置:
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/get_all_items").setViewName("all_items");
registry.addViewController("/login").setViewName("login");
}
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8" />
<title>all</title>
</head>
<body>
<table>
<tbody>
<tr th:each="item: ${items}">
<td th:text="${item.author}"></td>
<td th:text="${item.name}"></td>
</tr>
</tbody>
</table>
<a href="/login?logout">Log out</a>
</body>
</html>
UPDATE :
application.properties
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/spring_boot
spring.datasource.username=****
spring.datasource.password=****
spring.datasource.driver-class-name=org.postgresql.Driver