An error happened during template parsing (template: "class path resource [templates/index.html]")(有效轉)
轉自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/
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]")(有效轉)