簡體   English   中英

Spring Boot資源靜態文件夾

[英]Spring boot resource static folder

不久,我有構造如下的應用程序,問題是spring boot無法遞歸掃描靜態文件夾。 我的意思是,如果我將bootstrap.min.css放到static/css/bootstrap.min.css ,沒問題,但是如果我將其放入靜態文件夾static/bootstrap/bootstrap.min.css子包中的另一個文件夾中,就像在屏幕截圖,則我無法加載這些資源。 我該如何處理? 提前致謝。 在此處輸入圖片說明

您的網址沒有斜杠。

http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#link-urls

URL有不同類型:

  • 絕對網址: http//www.thymeleaf.org
  • 相對URL,可以是:
    • 相對頁面:user / login.html
    • 上下文相關:/ itemdetails?id = 3(服務器中的上下文名稱將自動添加)
    • 相對於服務器:〜/ billing / processInvoice(允許在同一服務器中的另一個上下文(=應用程序)中調用URL。
    • 相對於協議的網址://code.jquery.com/jquery-2.0.3.min.js

屏幕快照中的URL 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 ,然后使用以下href,而不是手動下載bootstrap.min.css:

th:href="@{/webjars/bootstrap/3.3.6/css/bootstrap.min.css}"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM