靜態資源是指----》 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>