1.
@RequestMapping("/fileupload2")
public String fileupload2(HttpServletRequest request,MultipartFile upload) throws Exception {
System.out.println("springMVC文件上传");
String path = request.getSession().getServletContext().getRealPath("/uploads");
//判断该路径是否存在
File file = new File(path);
if (!file.exists()){
file.mkdir();
}
String filename = upload.getOriginalFilename();
String uuid = UUID.randomUUID().toString().replace("-","");
filename=uuid+"_"+filename;
upload.transferTo(new File(path,filename));
return "success";
}
原文:https://www.cnblogs.com/aojie/p/13063154.html