今天做了一个博客,到构建框架部分了,但是在加载页面的时候,发生了一些问题,特此把这些问题记录下来,希望能帮助到你们。
首先出现的错误:
An error happened during template parsing (template: "class path resource [templates/index.html]")
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)
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 Resolve``rs (template: "index" - line 5, col 7)
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
在网上查阅博客和自己尝试之后:
我解决的步骤:
前篇:
如果报500或者404错误,可以先尝试删除tagert目录,在重新启动编译即可,如果没效果再尝试以下方法
- ` 在yml文件中加入配置
thymeleaf:
mode: HTML5
encoding: UTF-8
prefix: classpath:/templates/
suffix: .html
servlet:
content-type: text/html
cache: false
resources:
static-locations: classpath:/static/
- 在pom中加入依赖,在build中加入resources
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
<version>1.9.22</version>
</dependency>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
- 因为我的里面用到了引入js样式和属性和本地图片多种,就引入了一下配置
,不然会报错
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/xhtml">
不可以的可以尝试:之引入一中即可,一般是
<html lang="en" xmlns:th="http://www.thymeleaf.org">
- 其中引入本地图片,需要在后面加上th标签
<link rel="stylesheet" href="../static/css/me.css" th:href="@{css/me.css}">
本人做项目是小白一枚,如有
不足之处和缺乏之处,还请各位指出,谢谢大家!