使用IDEA 导入Thymeleaf 报错“template might not exist or might not be accessible”

本文详细解析了在Spring Boot项目中遇到的Thymeleaf模板加载失败问题,包括pom.xml配置检查、Maven资源过滤设置、Controller注解使用等关键步骤,帮助快速定位并解决错误。

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

错误名称:template might not exist or might not be accessible by any of the configured Template Resolvers

以下有几个错误点,耽误了2个多小时没排查出来,请仔细对照分析:

1. pom.xml 导入是否正确?

检查:在External Libraries ->Maven:org.thymeleaf 查看版本

若版本是3.0以上继续第二步。

2. 直接检查Target文件是否生成了Templates

若没有生成,则直接在pom.xml 中增加:

 

 

 

完整格式长这样:

<!--Maven资源过滤配置-->
<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.xml</include>
                <include>**/*.html</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>

我就是卡在这里了,没有增加html的导出设置,<includes>下只有properties,xml 。 

若非导包的问题,以下是其他排错方案:

方案一:检查 模板名称:index与Controller内return 的名称是否一致(注意return不要加“/”,即return "index" 而非 return "/index")

检查方案二: Controller控制器 使用 @Controller注解,而不用 @RestController;

补充:@Controller和@RestController的区别?

https://blog.youkuaiyun.com/lhq186/article/details/87894440

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值