【发布时间】:2017-05-10 03:17:13
【问题描述】:
我正在尝试按照http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html 的本教程学习如何将响应发送到 Thymeleaf 模板。但我收到此错误:找不到模板位置:类路径:/模板/(请添加一些模板或检查您的 Thymeleaf 配置)
我将 message.html 文件放在 Other Sources 目录和 <default package> 下的 src/main/resources 中。
所以结构看起来像:
一些项目
-其他来源
--src/main/资源
---<default package>
----message.html
我想知道为什么它显示在 <default package> 下而不是 <template> 下?会不会是问题?如果是这样我应该如何改变它?我正在使用 netbeans 和 Maven。请问有什么想法吗?这些是我在 pom.xml 中的依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
在控制器中我有
@RequestMapping(value = "message", method = RequestMethod.GET)
public String messages(Model model) {
model.addAttribute("messages", messageRepository.findAll());
return "message";
}
在视图中:
<ul th:each="message : ${messages}">
<li th:text="${message.id}">1</li>
<li><a href="#" th:text="${message.title}">Title ...</a></li>
<li th:text="${message.text}">Text ...</li>
</ul>
【问题讨论】:
标签: java spring maven spring-boot thymeleaf