最近在写springboot的项目,遇到了一些问题,与大家分享一下。因为thymeleaf是springboot推荐的模板引擎,所以选择了thymeleaf。集成很简单,直接添加maven依赖: pom文件加入下面内容即可: <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> 坑来了,springboot2.0之前的版本默认maven配置的是thymeleaf 2.*,thymeleaf 3.0以前的版本支持的模板模式(XML,HTML5,XHTML ,Legacy HTML5 等)除了Legacy HTML5之外,其他模式都必须是闭合的(标签),配置为Legacy HTML5模式可以支持不规范标签,但是还需要额外引入一个包用来处理代码 <dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> <version>1.9.22</version><!-- 版本自己调整,也可不动 --> </dependency> 其实处理这个问题很简单,就是把thymeleaf2指定版本到3.0以上就行了,如图springboot版本是1.5.12.RELEASE,设置thymeleaf版本如图: 代码: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version> </properties> <thymeleaf.version>3.0.9.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version> </properties> 到这里,thymeleaf集成完成。