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的.