org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/index.html]") at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241)
Caused by: org.attoparser.ParseException: Error resolving template [_fragments], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "index" - line 5, col 7) at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393)
Caused by: org.thymeleaf.exceptions.TemplateInputException: Error resolving template [_fragments], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "index" - line 5, col 7) at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)
2020-05-30 14:37:12.099 ERROR 5344 --- [nio-8080-exec-1] 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/index.html]")] with root cause org.thymeleaf.exceptions.TemplateInputException: Error resolving template [_fragments], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "index" - line 5, col 7) at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:869)
因为没有id为head的fragment的存在于_fragments下 ,所以没有解析找到他,你首先要创建一个(_fragments) html在其中创建一个id为head的fragment,
才能在index.html中用th:replace来引用他:
可以参考:
https://www.cnblogs.com/heavenbird/articles/9644985.html
有哪位大神帮一下忙吗
index.html ,第5行 ,表达式写错了。
你可以把index.html 代码贴出来。
<!DOCTYPE html> <!--<html lang="en" xmlns:th="http://www.thymeleaf.org">--> <!--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <head th:replace="_fragments :: head(~{::title})"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>首页</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css"> <link rel="stylesheet" href="../static/css/me.css" th:href="@{css/me.css}"> </head> <body>
第五行是找不到replace="_fragments吗
解析 _fragments 错误,看路径对着没,和这个模板页面里有问题没。
模板李没问题啊,就是这个_fragments在哪里
尝试把那个东西去掉了,还是报第一个错误
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/index.html]")
把index.html放在templates/index.html试试,模板解析器尝试从templates/index.html中解析index,未找到
可以截个resources文件的结构图吗
已经在那个目录下面了,而且使用这个标签的时候,会提示黄色,也会报错,不懂是为什么
试试这个:
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!--<head th:replace="_fragments :: head(~{::title})">--> <head > <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>首页</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css"> <link rel="stylesheet" href="../static/css/me.css" th:href="@{css/me.css}"> </head> <body> </body> </html>
使用thymeleaf的,注释掉XML的
index.html的后缀改为htm试试
index.htm
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <!--<head th:replace="_fragments :: head(~{::title})">--> <head > <meta charset="UTF-8"> <meta name="viewport" content="width=device-width,initial-scale=1.0"> <title>首页</title> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css"> <link rel="stylesheet" href="../static/css/me.css" th:href="@{css/me.css}"> </head> <body> </body> </html>
还是报这个问题呀
[THYMELEAF][http-nio-8080-exec-1] Exception processing template "index": An error happened during template parsing (template: "class path resource [templates/index.html]")
完整日志
输出的错误日志好像有些有提示第几行出错吧
谢谢各位大佬的辛苦,经过一天思考和查阅博客,上述是 ①_fragments的问题 ②xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/xhtml 要同时引入 ③不存在的属性删除,或者把类.属性换成类.get属性 ④xml文件引入<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
⑤引入本地图片 要在后面加上href="../static/css/me.css" th:href="@{css/me.css} ,这个依赖于http://www.thymeleaf.org,而引入属性和js等样式依赖于www.w3.org/1999/xhtml,所以我都同时引入试了一下,不懂是什么原理