在spring boot中使用thymeleaf开发前端代码时遇到的问题
集成thymeleaf后,所有的静态资源,只能加载一个index页面
其他页面,js,css,都无法加载
显示错误信息为
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Jan 20 15:01:38 CST 2020
There was an unexpected error (type=Not Found, status=404).
No message available
为了解决这个问题,花费了相当多的时间,尝试了各种方法,过滤器,拦截器,几乎说是把能找到的方法试了一遍
最后发现了一种极为简单的方法,就是修改spring boot 的配置文件
在你的配置文件中加入下面这一句,就行了
使用的spring boot 版本为2.1.6
spring:
resources:
static-locations: classpath:/static/,classpath:/view/,classpath:/public,classpath:/resources,classpath:/META-INF/resources,classpath:/templates