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>
    
  • 相关阅读:
    python给邮箱发送消息
    shell 的echo和 printf
    shell 基本运算符
    shell傳遞參數
    shell變量和數組
    pycharm的放大和缩小字体的显示 和ubunt的截圖工具使用 ubuntu上安装qq微信等工具
    flask的g对象
    mysqlcilent的安装
    Ubuntu安装 和 python开发
    使用python来建立http服务
  • 原文地址:https://www.cnblogs.com/acelance/p/12460793.html
Copyright © 2011-2022 走看看