我正在尝试按照http://www.thymeleaf.org/doc/articles/springmvcaccessdata.html上的本教程学习如何向Thymeleaf模板发送响应.但我得到这个错误:找不到模板位置:classpath:/ templates /(请添加一些模板或检查你的Thymeleaf配置)
我把message.html文件放在Other Sources目录下,在src/main/resources下面<default package>.
所以结构看起来像:
SomeProject -Other Sources --src/main/resources --- <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>
Run Code Online (Sandbox Code Playgroud)
在控制器中我有
@RequestMapping(value = "message", method = RequestMethod.GET)
public String messages(Model model) {
model.addAttribute("messages", messageRepository.findAll());
return "message";
}
Run Code Online (Sandbox Code Playgroud)
在视图中:
<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>
Run Code Online (Sandbox Code Playgroud)