欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

thymeleaf模块取消HTML5强校验

程序员文章站 2022-05-01 22:05:48
...

一、pom.xml添加以下依赖

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

二、spring配置文件添加以下配置信息

spring.thymeleaf.content-type=text/html  
spring.thymeleaf.cache=false  
spring.thymeleaf.mode=LEGACYHTML5

默认的mode是spring.thymeleaf.mode=HTML5的,所以是强校验的。

三、禁用模板缓存

thymeleaf使用模板缓存是默认的,这有助于改善应用程序的性能,因为模板只需编译一次,但是在开发过程中不能实时看到变更的效果,除非重启应用程序。

spring.thymeleaf.cache设置为false就能禁用thymeleaf模板缓存。

spring.thymeleaf.cache=false

使用其它模板也是类似的设置(默认情况下以下配置都是true,即开启模板缓存的)

spring.freemarker.cache=false
spring.groovy.template.cache=false
spring.velocity.cache=false

在开发环境推荐取消模板缓存,但是生产环境还是使用模板缓存可以给应用程序提升更大的性能。