當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
第六篇:Spring Boot 访问静态资源
生活随笔
收集整理的這篇文章主要介紹了
第六篇:Spring Boot 访问静态资源
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Spring Boot的默認(rèn)靜態(tài)資源的路徑為:
spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
優(yōu)先級從從高到低
一、Spring Boot 訪問靜態(tài)資源有二種方案
第一種方案(默認(rèn)):Spring Boot從classpath/static的目錄下面獲取靜態(tài)資源
目錄名稱必須要叫static
第一種形式:
- 在resource下面創(chuàng)建static目錄,添加a.jpg
- 瀏覽器訪問:http://localhost:8080/a.jpg
- 如果靜態(tài)資源放到不同的路徑,訪問時需要加上路徑
- 在 static下面創(chuàng)建images文件夾,把b.jpg復(fù)制即可
- 瀏覽器訪問:localhost:8080/images/b.jpg
第二種形式: - 新建index.html頁面,從頁面中獲取靜態(tài)與資源
在resource/static/和resource/static/images目錄下面把index.html頁面復(fù)制進(jìn)去。 - resource/static/index.html內(nèi)容為:
- resource/static/images/index.html內(nèi)容為:
- 瀏覽器測試:
第二種方案:
ServletContext的根目錄下:在 src/main/webapp 目錄名稱必須要叫webapp,
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"><title>springboot整合靜態(tài)資源方式1</title> </head> <body> springboot整合靜態(tài)資源方式1 <hr/> <img alt="gblfy" src="/images/1.jpg"> </body> </html>
本文源碼下載:
github地址:
https://github.com/gb-heima/Spring-Boot-Actual-Combat/tree/master/parent/spring-boot-chapter-6
總結(jié)
以上是生活随笔為你收集整理的第六篇:Spring Boot 访问静态资源的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1450. 在既定时间做作业的学生人数
- 下一篇: 用Jenkins自动化搭建测试环境_入门