0%

springboot项目使用Thymeleaf模板解析器

引入依赖包

1
2
3
4
5
6
7
8
9
10
11
12
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>

如果使用HTML5严格语法的话,可不加入nekohtml的依赖包
使用LEGACYHTML5的话,则必须加入nekohtml的依赖包

添加配置信息

选择项目中的bootstrap.yml或者application.yml等配置文件其中之一,添加如下内容

1
2
3
4
spring:
thymeleaf:
mode: LEGACYHTML5
cache: false

如果是application.properties,请按照spring.thymeleaf.mode= LEGACYHTML5的格式进行添加
添加cache是防止开发阶段,修改html文件厚始终不更新页面的问题

html页面使用该模板解析器

修改HTML页面,将html标签的开始标签更改为<html xmlns:th="http://www.thymeleaf.org">即可。