配置文件
# 端口号设置
server.port: 8082
# 应用程序的上下文设置
server.servlet.context-path: /wjec
# 静态文件的保存位置
web.upload-path: D:/data/
spring.web.resources.static-locations= classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${web.upload-path}
正确引用方式: 以/
开头
会从配置的静态文件夹路径下寻找相应的静态文件
<script th:src="@{/js/jquery.min.js}"></script>
<!--
转换为html之后
-->
http://localhost:8082/wjec/js/jquery.min.js
错误的引用方式:不以/
开头
会以当成普通的Get请求,从Controller层寻找匹配的URL
由于多加了一层/hehe
,所以找不到静态文件会报错
<script th:src="@{js/jquery.min.js}"></script>
<!--
转换为html之后
-->
http://localhost:8082/wjec/hehe/js/jquery.min.js