Controller转发到Thymeleaf模板页面报错TemplateInputException异常

本文详细解析了在SpringBoot项目中遇到的Thymeleaf模板引擎无法加载HTML模板的问题,并给出了具体的解决方案,包括如何在pom.xml中正确配置资源文件,确保HTML模板能够被打包并正确访问。

1、Controller

    @Controller
    public class TestController {
        @RequestMapping("/test")
        public String test(){
            return "index";
        }
    }

2、templates/index.html

 <!DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>wit</title>
    </head>
    <body>
         <p>hello,SpringBoot</p>
    </body>
    </html>

3、在浏览器访问

http://localhost:8080/test

报错

org.thymeleaf.exceptions.TemplateInputException: Error resolving template [index1], template might not exist or might not be accessible by any of the configured Template Resolvers

4、问题所在

之前为了将mapper下的XXXMapper.xml打包发布,在pom.xml文件中加入了如下,但并没有把html模板打包,在如下中加入注释的代码即可。

            <resources>
    			<resource>
    				<directory>src/main/java</directory>
    				<includes>
    					<include>**/*.xml</include>
    					<include>**/*.properties</include>
    					<include>**/*.yaml</include>
    					<!--<include>**/*.html</include>-->
    				</includes>
    				<filtering>true</filtering>
    			</resource>
    			<resource>
    				<directory>src/main/resources</directory>
    				<includes>
    					<include>**/*.xml</include>
    					<include>**/*.properties</include>
    					<include>**/*.yaml</include>
    					<!--<include>**/*.html</include>-->
    				</includes>
    				<filtering>true</filtering>
    			</resource>
    		</resources>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值