前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >An error happened during template parsing (template: “class path resource [templates/index.html]“)

An error happened during template parsing (template: “class path resource [templates/index.html]“)

作者头像
Rattenking
发布2021-02-01 11:03:19
3.7K0
发布2021-02-01 11:03:19
举报
文章被收录于专栏:Rattenking
场景

在开发springboot的时候,进行modelAndView 视图层映射的时候,一直出现

报错
代码语言:javascript
复制
An error happened during template parsing (template: "class path resource [templates/index.html]")

模板解析过程中发生错误(模板:“类路径资源[templates/index.html]”)

1.配置文件问题
代码语言:javascript
复制
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.servlet.content-type=text/html
spring.thymeleaf.encoding=utf-8
spring.thymeleaf.mode=LEGACYHTML5
spring.thymeleaf.cache=false
spring.mvc.static-path-pattern=/**
spring.resources.static-locations=classpath:/static/
2.注解@Controller

说是@Controller和@RestController功能不一样,将@Controller修改为@RestController在加上@ResponseBody(依然无效)

3.实体类没有get方法

说在映射的时候实体类没有get方法,为变量加上get就可以了(结果我本来就有get方法的)

4. pom.xml文件的build配置
代码语言:javascript
复制
<resources>
    <resource>
        <directory>sre/main/resources</directory>
    </resource>
</resources>
5.html文件头

原头:

代码语言:javascript
复制
<html xmlns:https="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org">

修改为:

代码语言:javascript
复制
<html  xmlns:th="http://www.thymeleaf.org">
总结
  1. 以上方法不一定解决你的问题,但是给你提供了思路,如果你出现相同问题,有其他解决方案,请回复进行完善,共同进步;
  2. 声明本人开发报此错误时,采用第一种方案,【配置文件】解决;
  3. 本文转载自,开发过程中的记录,以后出现相同错误,方便查找!
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/12/16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 场景
  • 报错
  • 1.配置文件问题
  • 2.注解@Controller
  • 3.实体类没有get方法
  • 4. pom.xml文件的build配置
  • 5.html文件头
  • 总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档