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/

他會自動導入到首頁



沒有留言:

張貼留言

invalid packging for parent POM com.xxxxxx:1.0SNAPSHOT must be "pom" but is "jar"

 出現在專案上面冒紅線, 並有紅字invalid packing...... 在本專案的原因是, 這裡有母子專案 有在子專案pom檔中聲明parent <parent> <artifactId> heima-leadnews-test </a...