欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring boot文件路徑映射配置代碼實例

 更新時間:2020年06月16日 08:31:11   作者:動力起點  
這篇文章主要介紹了Spring boot文件路徑映射配置代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

springboot配置本地資源映射路徑需要配置一下映射資源位置,下面來介紹一下過程。

1.添加配置類

package org.jcut.tools;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Component
public class MvcConfing implements WebMvcConfigurer {
  @Value("${imgpath}")
  String path;
  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    
//當請求服務(wù)器中帶有/imgs/的時候就是到指定路徑中找出對應(yīng)名字對應(yīng)圖片,其中**就代表匹配多層路徑下的名字
registry.addResourceHandler("/imgs/**").addResourceLocations("file:"+path);
  }
}

2.圖片上傳代碼

//添加展示圖片
     String t_img=UUID.randomUUID().toString();//商品展示圖片id
     boolean flag=false;
     for(MultipartFile ff:file1) {
       String tImgId=UUID.randomUUID().toString();
//寫入圖片名字的時候最好把獲取圖片映射名稱寫進去,方便獲取圖片
       timg.insert(new TImg(tImgId, t_img, "imgs/"+tImgId+".jpg"));
       try {
        ff.transferTo(new File(path+tImgId+".jpg"));
        flag=true;
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } 
     }

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論