springboot /thymeleaf 非严格模式

在springboot中使用thymeleaf时,须要在在application.properties中配置以下参数html

#thymeleaf start
classpath:/templates/*.html
spring.thymeleaf.mode = LEGACYHTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
#开发时关闭缓存,否则无法看到实时页面
spring.thymeleaf.cache=false
#thymeleaf end

其中spring

spring.thymeleaf.mode

默认值为: HTML5  为严格模式,此时html中apache

<meta charset="UTF-8">

若没有以/结尾则会报错缓存

报错:org.xml.sax.SAXParseException: 元素类型 "meta" 必须由匹配的结束标记 "</meta>" 终止。

此时只要在pom.xml中引入依赖springboot

<dependency>
	<groupId>net.sourceforge.nekohtml</groupId>
	<artifactId>nekohtml</artifactId>
	<version>1.9.22</version>
</dependency>

并将spring.thymeleaf.mode 的值由HTML5更改成为LEGACYHTML5便可app

相关文章
相关标签/搜索