1.在pom.xml中添加thymeleaf依赖:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
2.在application.properties(或者.yaml)中添加配置:
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
classpath:/后跟的是resources下的路径
注意: 这里不要写 spring.mvc.view.prefix 和 spring.mvc.view.suffix 因为我们引入了thymeleaf所以要用thymeleaf的.