template might not exist or might not be accessible by any of the configured

我遇到这个问题呢,项目环境是spring boot+dubbo+thymeleaf

在网上搜索了一上午,没有找到答案,然后呢,就采用我的葵花宝典:好好分析自己的项目环境(可能项目的错误是自己独有的)

我下列举下我在搜索过程中遇到的答案:

1.控制层上面的注解@Controller写成了@RestController(本注解=@Controller+@Responsebody)

2.原因是指向模板的路径前有斜杆/,就会出错,去掉就正常了(路径前不能带斜杆,类似相对路径的写法)

3.spring.thymeleaf.prefix=classpath:/templates

4.页面中的<meta charset="UTF-8" />

下面我列举一下几个遇到这种问题的注意事项

1.pom.xml文件

   <dependency>

       <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-thymeleaf</artifactId>

  </dependency>

2.hmtl页面放置在templates目录下(以根目录为例)

   1.页面名称:login.html

    方法的return “login”;  即可

   2.如果不是根目录的话,需要return “html/login”  (注意前面没有/

3.我的问题呢,比较奇葩,是因为我在pom.xml文件中添加了配置过滤(红色位置原来是没有添加的)

<!-- 如果不添加此节点mybatis的mapper.xml文件都会被漏掉。 -->
<!--<resources>
    <resource>
        <directory>src/main/java</directory>
        <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
        </includes>
        <filtering>false</filtering>
    </resource>
    <resource>
        <directory>src/main/resources</directory>
        <includes>
            <include>**/*.yml</include>
            <include>**/*.properties</include>
            <include>**/*.xml</include>
            <include>**/*.html</include>
        </includes>
        <filtering>false</filtering>
    </resource>
</resources>-->

这里我再多说一句哈,这个配置呢,应该是spring boot整合mybatis两种方式中的一种(基于Mapper文件的,基于注解的)

如果你是基于注解开发的,就没有mapper文件,也就用不到上面的文件了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值