yml配置之static-path-pattern 與 static-locations,靜態資源的訪問

spring:
mvc:
# 「spring.mvc.static-path-pattern」用於闡述HTTP請求地址,請求非controller地址,如js,css,img等訪問路徑須要加上static,
# 能夠不配置也能訪問圖片

# 而「spring.resources.static-locations」則用於描述靜態資源的存放位置。多個路徑(逗號隔開)中依次查找是否存在
static-path-pattern: /static/**
resources:
static-locations: classpath:/static/,file:D:\\
下面是一個訪問本地圖片的例子:

方框1:url中訪問路徑,這裏爲:localhost:8080/static/...css

方框2:本地圖片保存的路徑,image會根據d:\\和瀏覽器中輸入的圖片名字自動查找圖片spring

 

  

 

 

相關文章
相關標籤/搜索