spring boot不能直接访问templates目录中的html
在配置好thymeleaf后(使用@Controller注解,html文件放在templates下),发现还是无法访问html,可尝试如下处理。
方法一:
- 在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包才可以。
来源:CSDN
作者:青雉的腿
链接:https://blog.csdn.net/qq_30832781/article/details/103833208