Spring Boot + Thymeleaf 报错:ERROR 8592 org.thymeleaf.TemplateEngine

Spring Boot + Thymeleaf 报错:ERROR 8592 org.thymeleaf.TemplateEngine

报错详情

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: “class path resource [templates/…….html]”)

……ERROR 8592 — [p-nio-80-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: “class path resource [templates/…….html]”)] with root cause

问题定位与解决

1、定位

检查了Controller的返回值、路径拼写、注解等都未发现问题
还好有一个页面可以正常显示,于是进行交换对比,发现问题出在<!DOCTYPE>标签

2、解决

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

改为

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">

觉得莫名其妙,不过因为项目问题前端只能用这个使用很多淘汰标签所写的网页。Thymeleaf对前端要求较为严格,建议新项目使用H5标准。

扩展

这里提供一个关闭Thymeleaf严格语法校验的配置方法:

1、在pom.xml文件中添加依赖

<dependency>
   <groupId>net.sourceforge.nekohtml</groupId>
   <artifactId>nekohtml</artifactId>
   <version>1.9.21</version>
</dependency>

2、在application.properties中添加

spring.thymeleaf.mode=LEGACYHTML5
发布了118 篇原创文章 · 获赞 479 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/y_universe/article/details/91895401