2021年1月12日 星期二

[SpringBoot 1.5] 引入webjars和靜態頁面

 1 /webjars/**, 都去classpath:/Meta-INF/resources/webjars/找資源

webjars:以jar包的方式引入靜態資源

可以到網站 https://www.webjars.org/ 找尋需要用到的jar包

比方說我們找到Jquery3.3.1版本的Maven設置

<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>jquery</artifactId>
    <version>3.3.1</version>
</dependency>

然後我們將其貼到SpingBoot專案的pom.xml當中

重新download jar檔案

我們啟動服務後, 就可以在 

http://localhost:8080/webjars/jquery/3.3.1/jquery.js

找到完整的檔案

2 靜態資源可以被找到的路徑如下

"classpath:/META-INF/resources/",
"classpath:/resources/",
"classpath:/static/",
"classpath:/public/"
"/":當前項目的根路徑

3歡迎頁面

也就是index.html頁面

在所有靜態資源下的index.html頁面都會被找到

當你有此頁面的時候

只要輸入 http://localhost:8080/

他會自動導入到首頁



沒有留言:

張貼留言

量身訂做建議(37 歲,6 年 Java 後端工程師)from chatgpt

🎯 量身訂做建議(37 歲,6 年 Java 後端工程師) 1️⃣ 先看你的條件 年齡 37 屬於「中高年資」工程師,履歷上的 深度 / 系統設計能力 會比「語言多寡」更重要。 6 年 Java 後端 代表你在 Spring Boot、資料庫、API 設計...