SpringBoot集成 Thymeleaf采坑
按照网上的方式
-
编写 @Controller层 (注意这里不能用@RestController),因为要渲染页面,restController是以JSON格式返回
-
集成 Thymeleaf
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
-
编写 html 页面
启动后发现一直报404
排查方法:
-
修改日志级别,看debug日志
logging.level.root = debug
-
最后看到网上说可能是thymeleaf版本问题,添加
<properties> <thymeleaf.version>3.0.11.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version> </properties>
成功!
注:
1、控制层不能使用RestController, 要使用 Controller
2、日志级别设置
3、问题描述清楚