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

转自

场景

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

报错

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

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

1.配置文件问题

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配置

<resources>
    <resource>
        <directory>sre/main/resources</directory>
    </resource>
</resources>

5.html文件头

原头:

<html xmlns:https="http://www.w3.org/1999/xhtml"  xmlns:th="http://www.thymeleaf.org">

修改为:

<html  xmlns:th="http://www.thymeleaf.org">

总结

  1. 以上方法不一定解决你的问题,但是给你提供了思路,如果你出现相同问题,有其他解决方案,请回复进行完善,共同进步;
  2. 声明本人开发报此错误时,采用第一种方案,【配置文件】解决;
  3. 本文转载自,开发过程中的记录,以后出现相同错误,方便查找!

猜你喜欢

转载自blog.csdn.net/m0_38082783/article/details/111270464
今日推荐