博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
报错org.thymeleaf.exceptions.TemplateInputException: Error resolving template解决方案
阅读量:4125 次
发布时间:2019-05-25

本文共 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]
  1. 在controller层请求处理完了返回时,没有使用@RestController或@ResponseBody而返回了非json格式

这种情况下返回的数据thymeleaf模板无法解析,直接报错,本人正式因为这个原因才报错。

解决方案:可以将@Controller换成@RestController,不过需要注意有没有其他的方法返回了html页面,会导致返回的不是页面而是字符串;最好的方法就是在你所请求的方法上面加一个@ResponseBody即可。

  1. 在你的controller层对应的方法返回html路径及名称时,在前面多加了一个/ 。

例如return “/index”,正式这个/导致报错的,解决:去掉返回前面的/即可,例如return “/index” 。

  1. 在使用springboot的过程中,如果使用thymeleaf作为模板文件,则要求HTML格式必须为严格的html5格式,必须有结束标签,否则会报错。

解决办法如下:

在application.yml中添加以下配置

spring.thymeleaf.content-type: text/html spring.thymeleaf.cache: false spring.thymeleaf.mode: LEGACYHTML5
net.sourceforge.nekohtml
nekohtml
1.9.22
  1. 资源文件的路径被修改,如果你其他的请求都正常返回则可忽略这条。
    解决:在pom.xml文件的中加入
src/main/resources

目前本人就遇到上面四种报错原因,希望可以帮助到你。

转载地址:http://prhpi.baihongyu.com/

你可能感兴趣的文章
从山寨Spring中学习Spring IOC原理-自动装配注解
查看>>
实例区别BeanFactory和FactoryBean
查看>>
Spring后置处理器BeanPostProcessor的应用
查看>>
Spring框架的ImportSelector到底可以干嘛
查看>>
Mysql中下划线问题
查看>>
微信小程序中使用npm过程中提示:npm WARN saveError ENOENT: no such file or directory
查看>>
Xcode 11 报错,提示libstdc++.6 缺失,解决方案
查看>>
idea的安装以及简单使用
查看>>
Windows mysql 安装
查看>>
python循环语句与C语言的区别
查看>>
Vue项目中使用img图片和background背景图的使用方法
查看>>
vue 项目中图片选择路径位置static 或 assets区别
查看>>
vue项目打包后无法运行报错空白页面
查看>>
Vue 解决部署到服务器后或者build之后Element UI图标不显示问题(404错误)
查看>>
element-ui全局自定义主题
查看>>
facebook库runtime.js
查看>>
vue2.* 中 使用socket.io
查看>>
openlayers安装引用
查看>>
js报错显示subString/subStr is not a function
查看>>
高德地图js API实现鼠标悬浮于点标记时弹出信息窗体显示详情,点击点标记放大地图操作
查看>>