解决Thymeleaf静态资源的问题
2019-06-24 15:18:04    608    0    0
gaara

首先在配置完成thymeleaf之后,要在主配置文件中,配置好静态资源的文件配置:

  1. spring:
  2. mvc:
  3. static-path-pattern: /static/** #静态资源的请求方式
  4. resources:
  5. static-locations: classpath:/static/ # 静态资源的配置位置,可以写成一个数组配置多个目录

这时,你所有的直接指向static目录的请求都会指向到这个目录里。

thymeleaf中,对资源路径进行配置:

  1. <link rel="stylesheet" type="text/css" th:href="@{/static/css/button.css}" />
  2. <script type="text/javascript" th:src="@{/static/js/button.js}"></script>

我踩的一个坑,没有写成 “ /static/**” 而是写成了 “ static/**”

这样的话,就会把你的上下文加到你的路径上,导致访问路径变成你的请求上下文+资源路径,以至于404.

Pre: 旅行游记:日本(二)

Next: OAuth的问题及隐患

608
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
Table of content