一、使用版本
使用版本 springboot1.0.9.RELEASE
<thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>
使用starter
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
原因:spring-boot-starter-thymeleaf对html5默认校验要求高。一言不合就报错如下:
org.xml.sax.SAXParseException: 元素类型 "head" 必须由匹配的结束标记 "</head>
二、解决方案
1. 启用不严格检查html
<!--启用不严格检查html-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
2. Legacy模式
spring.thymeleaf.mode=LEGACYHTML5
3. 关闭缓存(不是必要步骤)
spring.thymeleaf.cache=false