thymeleaf标签必须由匹配的结束标记终止

时间:2023-03-09 15:45:41
thymeleaf标签必须由匹配的结束标记终止

问题描述

springboot使用Thymeleaf标签时会报元素类型必须由匹配的结果标记终止。 
如下所示

thymeleaf标签必须由匹配的结束标记终止

如果我们一个个的给这些元素后面加上终止标记也是件很麻烦的事~~~~

解决办法

方法一: 
在pom.xml中的 properties 中指明Thymeleaf标签的版本号即可

<properties>
<project.build.sourceEncoding>UTF-</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<!--添加如下两行代码指定Thymeleaf标签的版本-->
<thymeleaf.version>3.0..RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.0.</thymeleaf-layout-dialect.version>
</properties>

但是我表示这是一个坑,因为我在pom.xml中加了这两行代码,导致了我使用springsecurity的<sec:authorize>标签时总是标签不起作用,后来通过两天的时间才找出是这里为以后的程序埋下了一个深深的坑啊!!!

于是才有了下面的方法二·······

方法二:
在pom.xml中添加依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>

  application.properties中

spring.thymeleaf.mode=LEGACYHTML5

springboot2.0以后没有这样的问题