1,首先确认是否导入thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2,确认自己写的.html为后缀的文件是否放到 resources/templates/ 文件夹下。
为什么非要放到这个路径下?查看thymeleaf的源码 ThymeleafProperties类,可以看到thymeleaf默认渲染的路径和后缀,所以我们只需在controller类中返回文件的名称,thymeleaf就会帮我们自动渲染了,这和springmvc中视图的渲染类似。
3,确认自己的Controller类要放在与 有@SpringBootApplication注解的启动类相同包或者子包下。
4,确认Controller类不能使用 @RestController 或者 @ResponseBody注解,否则会直接return该字符串,是return不到目标html的。