springboot使用thymeleaf时报html没有结束标签

在使用springboot的过程中,如果使用thymeleaf作为模板文件,则要求HTML格式必须为严格的html5格式,必须有结束标签,否则会报错!解决办法如下:

1、你可以使用严格的标签,也就是每个标签都有结束标签,这种可能比较麻烦

2、在application.properties中增加spring.thymeleaf.mode=LEGACYHTML5,即声明thymeleaf使用非严   格的html。启动之后访问页面会报如下错误:


org.thymeleaf.exceptions.ConfigurationException: Cannot perform conversion to XML from legacy HTML: The nekoHTML library is not in classpath. nekoHTML 1.9.15 or newer is required for processing templates in "LEGACYHTML5" mode [http://nekohtml.sourceforge.net]. Maven spec: "net.sourceforge.nekohtml::nekohtml::1.9.15". IMPORTANT: DO NOT use versions of nekoHTML older than 1.9.15.

at org.thymeleaf.templateparser.html.AbstractHtmlTemplateParser.parseTemplate(AbstractHtmlTemplateParser.java:90) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]

at org.thymeleaf.TemplateRepository.getTemplate(TemplateRepository.java:278) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]

at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1104) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]

at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1060) ~[thymeleaf-2.1.5.RELEASE.jar:2.1.5.RELEASE]

上面的异常已经说的很清楚了,需要依赖nekoHTML 1.9.15 or newer的版本。maven依赖如下

<dependency>

<groupId>net.sourceforge.nekohtml</groupId>

<artifactId>nekohtml</artifactId>

<version>1.9.22</version>

</dependency>

现在就可以正常访问了。

时间: 2024-08-05 15:23:08

springboot使用thymeleaf时报html没有结束标签的相关文章

SpringBoot使用thymeleaf和layui时遇到的问题

在使用thymeleaf时报错An error happened during template parsing (template: "class path resource [templates/mainPage/main.html]" - line 134, col 168)我最后找了 很久发现报错的那一行有个HTML结束标签不对,改好之后页面就可以正常显示了. 每个人报的错误都可能不同,仔细看一下报错的内容和具体行数. thymeleaf+layui加载页面渲染时Templat

Spring Boot入门系列六( SpringBoot 整合thymeleaf)

SpringBoot 整合thymeleaf 一.什么是Thymeleaf模板 Thymeleaf是一款用于渲染XML/XHTML/HTML5内容的模板引擎.类似JSP,Velocity,FreeMaker等,它也可以轻易的与Spring MVC等Web框架进行集成作为Web应用的模板引擎.与其它模板引擎相比,Thymeleaf最大的特点是能够直接在浏览器中打开并正确显示模板页面,而不需要启动整个Web应用.它的功能特性如下: @Controller中的方法可以直接返回模板名称,接下来Thyme

springboot整合Thymeleaf模板引擎

引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>nekohtml</groupId&g

三、SpringBoot整合Thymeleaf

三.SpringBoot整合Thymeleaf As well as REST web services, you can also use Spring MVC to serve dynamic HTML content. Spring MVC supports a variety of templating technologies, including Thymeleaf, FreeMarker, and JSPs. Also, many other templating engines

SpringBoot中Thymeleaf基本语法

SpringBoot中Thymeleaf基本语法 本节咱们介绍Thymeleaf的基本语法 学习视频: http://www.itlaoqi.com/chapter/1688.html 源码地址: QQ群 814077650 , 群共享中自助下载 老齐的官网: itlaoqi.com (更多干货就在其中) 页面中显示Model中的变量 使用${}获取Model中的属性值 在标签中增加th:text显示数据 或在标签体增加[[表达式]]显示数据 <td th:text="${emp.empn

SpringBoot中Thymeleaf自定义配置项

SpringBoot中Thymeleaf自定义配置项 SpringBoot在模板引擎中支持Thymeleaf自定义可配置项,其配置文件名必须是messages.properties 学习视频: http://www.itlaoqi.com/chapter/1688.html 源码地址: QQ群 814077650 , 群共享中自助下载 老齐的官网: itlaoqi.com (更多干货就在其中) messages.properties app.report.name=SAMDI上海分公司员工信息表

springboot支持thymeleaf 07

thymeleaf也是一模板技术,与freemarker类似,本文讲述springboot如何整合thymeleaf. 1.环境约束 win10 64位操作系统 idea2018.1.5 maven-3.0.5 jdk-8u162-windows-x64 2.前提约束 完成springboot创建web项目 https://www.jianshu.com/p/de979f53ad80 注意:笔者创建项目的时候约束的包前缀是net.wanho.springboot.thymeleaf,读者可以自行

Springboot+JPA+Thymeleaf 校园博客完整小网站

本文所属[知识林]:http://www.zslin.com/web/article/detail/35 此项目是一个比较简易的校园博客.麻雀虽小五脏俱全,虽然是比较简易的但是涉及的知识点还是比较全面的. 此项目涵盖了[知识林]中Springboot和Thymeleaf中所有知识点的内容. 主要功能有: 系统管理 系统初始化 菜单管理 角色管理 用户管理 系统配置管理 用户注册 邮件验证码实现 用户登陆 找回密码 博文分类管理 添加分类 修改分类 博文管理 添加博文 修改博文 博文评论(未实现)

HTML的结束标签问题

根据w3c的原则,xml的每个开始标签必须有一个结束标签与之对应,也就是<html>必须要有</html>结束,才是一个完整的元素,除非它是一个自封闭标签,自封闭就是<img src="... " />之类的标签.html是xml的子级,所以也要遵循xml的原则,这是标准.所以,<meta charset=UTF-8> 不加/> 来结束,不符合标准,只适合html 4.0以前的版本,目前大多网站为了seo和多浏览器支持,都采用xht