我很快就有了如下结构的应用程序,问题是spring boot不会递归扫描静态文件夹。我的意思是
如果我把bootstrap.min.css放到static/css/bootstrap.min.css
它没关系,但是如果我放入静态文件夹static/bootstrap/bootstrap.min.css
的子包中的另一个文件夹,就像在屏幕截图中那样我无法加载这些资源。我怎么处理这个?提前致谢。
答案 0 :(得分:2)
您的网址没有前导斜杠。
http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#link-urls
有不同类型的网址:
- 绝对网址:http://www.thymeleaf.org
- 相对网址,可以是:
- Page-relative:user / login.html
- 上下文相关:/ itemdetails?id = 3(服务器中的上下文名称将自动添加)
- 服务器相对:〜/ billing / processInvoice(允许在同一服务器中调用其他上下文(=应用程序)中的URL。
- 协议相对网址://code.jquery.com/jquery-2.0.3.min.js
屏幕截图中的网址 bootstrap / css / bootstrap.min.css 是页面相对的。
您想要的是与上下文相关的URL。当您的文件位于 src / main / resources / static / css / bootstrap.min.css 中时,请使用:
th:href="@{/css/bootstrap.min.css}"
当它位于 src / main / resources / static / bootstrap / bootstrap.min.css 中时,请使用:
th:href="@{/bootstrap/bootstrap.min.css}"
此外,我建议您使用Bootstrap WebJar而不是手动下载bootstrap.min.css,然后使用以下href:
th:href="@{/webjars/bootstrap/3.3.6/css/bootstrap.min.css}"