controller:
//上傳圖片
@RequestMapping("/uploadPic.do")
public void uploadPic(HttpServletRequest request,
@RequestParam(required = false) MultipartFile pic)throws IOException{
//上傳檔案路徑
String path = request.getSession().getServletContext().getRealPath("/upload/");
//上傳檔案名
String fileName = pic.getOriginalFilename();
File filePath = new File(path,fileName);
//判斷路徑是否存在,如果不存在就創建一個
if(!filePath.getParentFile().exists()){
filePath.getParentFile().mkdir();
}
//將上傳檔案保存到一個目標檔案中
pic.transferTo(new File(path+File.separator+fileName));
}
專案:

怎么將圖片上傳路徑更改為webapp下的upload目錄?真心感謝。
uj5u.com熱心網友回復:
同問?樓主解決了嗎轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/128671.html
標籤:其他技術討論專區
