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文件,也就用不到上面的文件了。

猜你喜欢

转载自blog.csdn.net/AinUser/article/details/81563462
今日推荐