方法 /** 接受的 */
@RequestMapping("/upload") public String upload(MultipartFile uploadFile, HttpServletRequest req){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd"); String realPath ="指定的文件存储路径" String format = sdf.format(new Date()); File folder = new File(format+realPath); if(!folder.isDirectory()){ folder.mkdirs(); } String oldName = uploadFile.getOriginalFilename(); Long sixe=uploadFile.getSize(); String newName = UUID.randomUUID().toString()+oldName.substring(oldName.lastIndexOf("."),oldName.length()); try{ uploadFile.transferTo(new File(folder,newName)); String filePath = req.getScheme()+"://"+req.getServerName()+":"+req.getServerPort()+"/uploadFile"+format+newName ; return filePath ; } catch (IOException e) { e.printStackTrace(); } return "上传失败" ; }