1. 程式人生 > >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]")(有效轉)

路徑資源 rec mod error oot 修改 uri 解決 text

轉自https://blog.csdn.net/qq_41426326/article/details/88837112

在開發springboot的時候,進行modelAndView 視圖層映射的時候,一直出現

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

模板解析過程中發生錯誤(模板:“類路徑資源[templates/index.html]”)

在向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和@RestController功能不一樣,將@Controller修改為@RestController在加上@ResponseBody(依然無效)、

3.說在映射的時候實體類沒有get方法,為變量加上get就可以了(結果我本來就有get方法的)

4.還有說在pom.xml文件下的build配置(都不是這個錯誤的解決方案)

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

最後小編早上智商最高峰的時候發現了這個小小小問題

在這附上小編index.html的文件開頭,就是因為加了

https: xmlns:https="http://www.w3.org/1999/xhtml"

xmlns:th="http://www.thymeleaf.org"
導致調用的時候原本要調用第二句話的代碼調用了第一句代碼中的方法發生錯誤,把第一句代碼刪除就可以了

小編總結了一下,一般系統出現以下錯誤

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

大家可以去看看視圖層,並不是java代碼出現錯誤.

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