springboot 用thymeleaf 出现Error resolving template template might not exist or might not be acceacce问题
springboot 用thymeleaf 出现的错误问题
Error resolving template template might not exist or might not be accessible
原因是因为 thymeleaf 采用严格的HTML5 规则,必须要有结束标签。否则会包上面的错误
解决办法
spring: #声明thymeleaf使用非严格的html。 thymeleaf: content-type: text/html mode: LEGACYHTML5 cache: false
会出现如下错误:
缺少依赖
<dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> <version>1.9.22</version> </dependency>
如果还未解决,可能原因是:
templates 文件名是否正确
controller中 return "/index" 页面不能有 /
以上方法无解决办法:那只能是springboot版本问题了。
我在
1.5.17.RELEASE 这个版本下,以上都改过了,还是报模板找不到错误。
后来将springboot版本 改为
2.1.0.RELEASE 成功运行了。