SpringBoot處理靜態資源的兩種方式


靜態資源是指----》 CSS、JS之類的文件

首先創建SpringBoot Web項目

添加Spring Boot Web Starter

1         <dependency>
2             <groupId>org.springframework.boot</groupId>
3             <artifactId>spring-boot-starter-web</artifactId>
4         </dependency>

 

第一種方式(將靜態資源文件放至靜態資源文件夾)

  ① “/”  當前項目的根路徑

  ②classpath:/META-INF/resources/  

  ③classpath:/resources/

  ④classpath:/static/

  ⑤classpath:/public/

 

 

 

* 項目的歡迎頁會在上面的5個地址尋找index.html

* 項目的頁面圖標會在上面的5個地址尋找favicon.ico

* 可以通過配置文件來覆蓋默認的靜態資源文件夾地址

  

1 spring.resources.static-locations=classpath:/coreqi/

 

 

第二種方式(使用webjars)

webjars是一種以jar包方式引入靜態資源

https://www.webjars.org/

所有的/webjars/**請求都將去classpath:/META-INF/resources/webjars/去尋找資源

例如:

  

1         <dependency>
2             <groupId>org.webjars</groupId>
3             <artifactId>jquery</artifactId>
4             <version>3.3.1-1</version>
5         </dependency>

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM