Spring Boot Thymeleaf 解析出错

 缘由就是Spring Boot 默认依赖的是低版本的Thymeleaf,低版本的Thymeleaf不能解析HTML5格式的HTML代码,而是把HTML当成XML解析,全部标签必须闭合!
 可是!我试过把标签都闭合以后仍是会报错,并且每一个标签都闭合实在是很繁琐的过程,就另寻解决方案了。最后在Github中下载了一份源码(Github源码地址)。查看源码后,找到解决方法以下:
pom.xml中的properties标签中加入以下代码java

<!-- 覆盖thymeleaf版本依赖 -->
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-extras-java8time.version>3.0.0.RELEASE</thymeleaf-extras-java8time.version>
<thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>

 这段代码是将Spring Boot 默认依赖的thymeleaf版本替换为咱们定义的版本,这里为3.0.2.RELEASE。 3.x 以上的 thymeleaf 已经支持HTML5格式HTML代码解析,报错的问题就解决了!git

相关文章
相关标签/搜索