本文共 1572 字,大约阅读时间需要 5 分钟。
最近在使用springboot+thymeleaf写程序的时候,一直报错org.thymeleaf.exceptions.TemplateInputException: Error resolving template硬是搞了整整一天才解决,因为自己踩过坑了,所以,在这里,本人给出目前我所搜集到的所有报这个错的情况的解决方案。
org.thymeleaf.exceptions.TemplateInputException: Error resolving template "xxx/xxx", template might not exist or might not be accessible by any of the configured Template Resolvers at org.thymeleaf.engine.TemplateManager.resolveTemplate(TemplateManager.java:865) ~[thymeleaf-3.0.2.RELEASE.jar:3.0.2.RELEASE] at org.thymeleaf.engine.TemplateManager.parseAndProcess(TemplateManager.java:608) ~[thymeleaf-3.0.2.RELEASE.jar:3.0.2.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1087) [thymeleaf-3.0.2.RELEASE.jar:3.0.2.RELEASE] at org.thymeleaf.TemplateEngine.process(TemplateEngine.java:1061) [thymeleaf-3.0.2.RELEASE.jar:3.0.2.RELEASE]
这种情况下返回的数据thymeleaf模板无法解析,直接报错,本人正式因为这个原因才报错。
解决方案:可以将@Controller换成@RestController,不过需要注意有没有其他的方法返回了html页面,会导致返回的不是页面而是字符串;最好的方法就是在你所请求的方法上面加一个@ResponseBody即可。
例如return “/index”,正式这个/导致报错的,解决:去掉返回前面的/即可,例如return “/index” 。
解决办法如下:
在application.yml中添加以下配置
spring.thymeleaf.content-type: text/html spring.thymeleaf.cache: false spring.thymeleaf.mode: LEGACYHTML5
net.sourceforge.nekohtml nekohtml 1.9.22
src/main/resources
目前本人就遇到上面四种报错原因,希望可以帮助到你。
转载地址:http://prhpi.baihongyu.com/