org.thymeleaf.exceptions.TemplateInputException: Error resolving template [xxx], template might no

本文解决了一个常见的SpringBoot与Thymeleaf整合时的配置错误,详细阐述了因配置文件中前缀路径缺失斜杠导致的TemplateInputException异常,以及如何正确配置前缀路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值