在springboot中約定大於配置,當然對靜態資源也有預設的約定。
spring boot 預設將 /** 所有訪問對映到以下目錄:
下面我將通過乙個小demo來給大家展示一下classpath:/static
classpath:/public
classpath:/resources
classpath:/meta-inf/resources
所以大家在訪問靜態資源時就不需要加/static,/public這些字首了,人家springboot都給你預設映**,你再新增不是畫蛇添足嗎?
專案路徑
controller正確使用姿勢:
在瀏覽器位址列輸入 http://localhost:8080/@controller
public class hellocontroller
}
下面就是顯示的效果了(大家自己去意會)
總結:在springboot有些配置它已經預設配置好了,大家要注意這些預設配置,不要在這上面不停的採坑。
springboot關於預設靜態資源訪問路徑定義及自定義設定
spring boot 靜態資源
springboot中,預設的靜態資源路徑有 配置在resourceproperties類中 private static final string classpath resource locations 優先順序 靜態資源路徑 例如 webmvcautoconfiguration自動裝配類中,可...
SpringMVC REST 風格靜態資源訪問配置
1 在web.xml中使用預設servlet處理靜態資源,缺點是如果靜態資源過多,則配置量會比較大,一旦有遺漏,則會造成資源無法正常顯示或404錯誤。2 在springmvc配置檔案中配置 我的所有靜態資源都在webcontent static 之下,下有如下目錄webcontent static ...
springboot載入靜態資源
使用springboot寫了簡單的web專案,頁面使用jsp檔案 但是靜態資源js 載入不到,看了下官方文件發現是因為路徑不對 所以專案靜態資源應該配置在根路徑下這四個資料夾中是可以直接訪問到的 meta inf resources,public,resources,static下的資源,對映路徑 ...