2020.06.07 SpringMVC中文件上传方式

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";
}
posted @ 2020-06-08 00:04  ByLir  阅读(79)  评论(0)    收藏  举报