• 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 6 socket编程
    Python 5 面向对象进阶
    Python 4 面向对象
    Python 3 常用模块
    Python基础 2
    Python基础 1
    Django之会议室预预订
    vscode 修改快捷键 (回到上一处光标位置,下一处光标位置)
    C 库函数
    C 库函数
  • 原文地址:https://www.cnblogs.com/acelance/p/12460793.html
Copyright © 2020-2023  润新知