按顺序来,选择一个或多个看看能否解决问题。
1、是否导入了与springboot相适配的thymeleaf依赖包
<!--Thymeleaf模板-->
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
2、templates文件夹不要建错名字了,并且不要放在static里,放在resources下。
3、有没有在application.properties或application.yml里配置了thymeleaf,这里我方一下我的application.properties。
#Thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode=HTML
spring.mvc.static-path-pattern=/static/**
4、template需要使用@Controller返回视图,使用@RestController只会返回数据到页面,而不会跳转页面。
5、是否在pom.xml里的最下面的build里加了resources,加了的话看下有没有加html后缀。
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.html</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>**/*.html</include>
<include>**/*.ini</include>
</includes>
</resource>
</resources>
6、是否加了拦截器,没放行你要跳转的接口。(没使用拦截器的,可以忽略此条)