spring boot访问templates下的html返回404

末鹿安然 提交于 2020-01-11 03:48:40

spring boot不能直接访问templates目录中的html

在配置好thymeleaf后(使用@Controller注解,html文件放在templates下),发现还是无法访问html,可尝试如下处理。

方法一:

  1. 在application.properties中改变默认模板的位置和后缀,将默认的spring.thymeleaf.*** 改成 spring.mvc.view.***
    在这里插入图片描述
    2.将html文件放在resources/static下
    在这里插入图片描述
    然后启动项目访问即可。

方法二:
application.properties里写
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8

方法三:
<thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
<thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>

方法四:
网络上很多人说是jar包依赖的问题:
说是有可能是maven引入的包有问题导致的。但是该问题无法通过在项目中清理后重新构建来修复(本人尝试无用),只能把配置的对应的maven m2目录清空,然后打开eclipse以后重新构建的时候让maven重新下载所需jar包才可以。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!