zoukankan      html  css  js  c++  java
  • 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>
    
  • 相关阅读:
    Power of Cryptography
    Radar Installation
    Emag eht htiw Em Pleh
    Help Me with the Game
    89. Gray Code
    87. Scramble String
    86. Partition List
    85. Maximal Rectangle
    84. Largest Rectangle in Histogram
    82. Remove Duplicates from Sorted List II
  • 原文地址:https://www.cnblogs.com/acelance/p/12460793.html
Copyright © 2011-2022 走看看