1. 关闭html模式标签解析严格模式
这个官方称呼可能不是这个,就是默认配置下,thymeleaf对.html的内容要求很严格,比如<meta charset="UTF-8" />,如果少最后的标签封闭符号/,就会报错而转到错误页。也比如你在使用Vue.js这样的库,然后有<div v-cloak></div>这样的html代码,也会被thymeleaf认为不符合要求而抛出错误。通过设置thymeleaf模板可以解决这个问题,下面是具体的配置:
spring:
#devtools
devtools:
restart:
enabled: true
#thymeleaf
thymeleaf:
cache: false
check-template: true
check-template-location: true
encoding: utf-8
#servlet:
content-type: text/html
enabled: true
mode: LEGACYHTML5 //替换模式的html5模式
prefix: classpath:/templates/
suffix: .html
LEGACYHTML5需要搭配一个额外的库NekoHTML才可用
项目中使用的构建工具是Maven添加如下的依赖即可完成:
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml<