默认配置下,thymeleaf对.html的内容要求很严格,比如<meta charset="UTF-8" />,如果少最后的标签封闭符号/,就会报错而转到错误页。也比如你在使用Vue.js这样的库,然后有<div v-cloak></div>这样的html代码,也会被thymeleaf认为不符合要求而抛出错误。

通过设置thymeleaf模板可以解决这个问题,下面是具体的配置:

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

LEGACYHTML5需要搭配一个额外的库 NekoHTML才可用

项目中使用的构建工具是Maven添加如下的依赖即可完成:

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


Logo

前往低代码交流专区

更多推荐