thymeleaf使用th:fragment配置公用模板代码时,默认所有的标签必须关闭,即类似<img></img>或<img/>这类形式,但是html代码不可能按照严格的XML格式进行编写,所以需要一个方法来配置标签不需要关闭:
- maven添加
nekohtml依赖:
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
-
application.yml配置参数:
spring:
thymeleaf:
mode: LEGACYHTML5
重启springboot就可以生效了