错误:org.xml.sax.SAXParseException: Element type “XX” must be followed by either attribute specifications, “>” or “/>”.XX
出现的问题:
我每次用springboot+thymeleaf 写html页面时或copy别人的项目时,在本机上运行时总出现这种问题,一个一个的找标签太麻烦了。
出现问题的原因:
thymeleaf模板引擎默认是Template modes:HTML5解析的,解析比较严格,对html的内容要求很严格,假如不符合规范,那么就会报错。
解决:thymeleaf模板对没有结束符的HTML5标签解析出错的解决办法
1 在pom文件中添加依赖
<!--添加这个依赖就不会严格检查HTML-->
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
2 在 application.properties配置文件中配置
2.1 关闭缓存
#spring.thymeleaf.cache=false
2.2 Content-Type值
#spring.thymeleaf.content-type=text/html
2.3 应用于模板的模板模式
#spring.thymeleaf.content-type=text/html