springboot中配置addResourceHandler和addResourceLocations,使得可以從磁盤中讀取圖片、視頻、音頻等


磁盤目錄

 

 

 

 

 

WebMvcConfig的代碼

 

//對靜態資源的配置 @Override public void addResourceHandlers(ResourceHandlerRegistry registry) {

   String os = System.getProperty("os.name");

   if (os.toLowerCase().startsWith("win")) {  //如果是Windows系統 registry.addResourceHandler("/smallapple/**")
            // /apple/**表示在磁盤apple目錄下的所有資源會被解析為以下的路徑 .addResourceLocations("file:G:/itemsource/smallapple/") //媒體資源 .addResourceLocations("classpath:/META-INF/resources/");  //swagger2頁面 } else {  //linux 和mac registry.addResourceHandler("/smallapple/**")
            .addResourceLocations("file:/resources/smallapple/")   //媒體資源 .addResourceLocations("classpath:/META-INF/resources/");  //swagger2頁面; }
}

 

數據庫中路徑

 

 

測試:

 

 


免責聲明!

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



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