springboot+html+thymeleaf,使用模板语法出现 Cannot resolve MVC View ‘xxx‘,访问网页显示404或者500, 问题解决

按顺序来,选择一个或多个看看能否解决问题。

1、是否导入了与springboot相适配的thymeleaf依赖包

<!--Thymeleaf模板-->
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-java8time</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.nekohtml</groupId>
            <artifactId>nekohtml</artifactId>
            <version>1.9.22</version>
        </dependency>

2、templates文件夹不要建错名字了,并且不要放在static里,放在resources下。 

 

3、有没有在application.properties或application.yml里配置了thymeleaf,这里我方一下我的application.properties。

#Thymeleaf
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.mode=HTML
spring.mvc.static-path-pattern=/static/**

4、template需要使用@Controller返回视图,使用@RestController只会返回数据到页面,而不会跳转页面。

 5、是否在pom.xml里的最下面的build里加了resources,加了的话看下有没有加html后缀。

 

<resources>
      <resource>
           <directory>src/main/java</directory>
           <includes>
           <include>**/*.xml</include>
           <include>**/*.html</include>
           </includes>
       </resource>
       <resource>
           <directory>src/main/resources</directory>
           <includes>
           <include>**/*.xml</include>
           <include>**/*.properties</include>
           <include>**/*.html</include>
           <include>**/*.ini</include>
           </includes>
       </resource>
</resources>

6、是否加了拦截器,没放行你要跳转的接口。(没使用拦截器的,可以忽略此条)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值