thymeleaf使用mode: LEGACYHTML5非严格模式Html需要添加nekohtml依赖否则报错

在使用springboot的过程中,如果使用thymeleaf作为模板文件,则要求HTML格式必须为严格的html5格式,必须有结束标签,否则会报错!
但是如果使用严格的Html5标签编写页面那么就会很麻烦,编程效率低,所以需要像一般的Html一样编写的话,
解决办法如下:
  1、在application.yml中增加spring: thymeleaf: mode: LEGACYHTML5参数配置,开启使用非严格的HTML

spring:
  application:
    name: myshop-service-user-consumer
  thymeleaf:
    cache: false # 开发时关闭缓存,不然没法看到实时页面
    mode: LEGACYHTML5 # 用非严格的 HTML
    encoding: UTF-8
    servlet:
      content-type: text/html

server:
  port: 8601

但是如果配置了spring: thymeleaf: mode那么就需要额外引用net.sourceforge.nekohtml:nekohtml依赖,否则会报错;

<!-- 在使用thymeleaf是必须使用以下两个依赖,否则无法找到templates下的html视图对象 -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
    <groupId>net.sourceforge.nekohtml</groupId>
    <artifactId>nekohtml</artifactId>
</dependency>
posted @ 2020-03-11 10:21  acelance  阅读(5050)  评论(0编辑  收藏  举报