关于使用springboot和thymeleaf中出现的加载页面问题 和 500 引入错误

今天做了一个博客,到构建框架部分了,但是在加载页面的时候,发生了一些问题,特此把这些问题记录下来,希望能帮助到你们。

首先出现的错误:

  1. An error happened during template parsing (template: "class path resource [templates/index.html]")
  2. 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)
  3. 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)
  4. 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目录,在重新启动编译即可,如果没效果再尝试以下方法

  1. ` 在yml文件中加入配置
thymeleaf:
    mode: HTML5
    encoding: UTF-8
    prefix: classpath:/templates/
    suffix: .html
    servlet:
    content-type: text/html
    cache: false
  resources:
  static-locations: classpath:/static/
  1. 在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>
  1. 因为我的里面用到了引入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">
  1. 其中引入本地图片,需要在后面加上th标签
<link rel="stylesheet" href="../static/css/me.css" th:href="@{css/me.css}">

本人做项目是小白一枚,如有
不足之处和缺乏之处,还请各位指出,谢谢大家!

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值