org.thymeleaf.exceptions.TemplateInputException: Error resolving template [xxx], template might not exist or might not be accessible by any of the configured Template Resolvers
springboot整合thymeleaf得是后出现的错误,找不到返回的页面,引起这样的错误有很多种情况,我直说我遇到的。我出现这这情况是因为配置文件出现了问题。在 prefix 前缀的配置中少加了一个 "/"
原来的配置文件:
## thymeleaf模板设置
thymeleaf:
prefix: classpath:/templates #这是我错误的配置
## prefix: classpath:/templates/ #这是正确的配置,修改过后的配置
suffix: .html
mode: HTML
encoding: utf-8
servlet.content-type: text/html
check-template-location: true #检查模板路径是否存在
cache: false
项目目录如下:
controller如下:
解决问题的方式就是配置文件的 prefix 前缀的路径少加了一个“/”,这个/很重要,大家不要忘记加了。正确的配置文件:
## thymeleaf模板设置
thymeleaf:
prefix: classpath:/templates/
suffix: .html
mode: HTML
encoding: utf-8
servlet.content-type: text/html
check-template-location: true #检查模板路径是否存在
cache: false