前端实现多文件上传,后端接收处理

前端实现:


后端实现:

@RequestMappiing(value="upload",method=RequestMthod.POST)
@ResponseBody
public String uploadFile(@RequestParam("data") MultipartFile[] files, HttpServletRequest request)throws Exception{
String filePath = request.getServletContext().getRealPath("/")+"upload/";
File tmpFile = new File(filePath);

//判断是否存在该文件夹,若不存在则创建文件夹
if(!tmpFile.exists()){
tmpFile.mkdir();
}

for(MultipartFile file:files){
file.transferTo(new File(filePath+file.getOriginalFilename()));
}
return "success";
}

你可能感兴趣的:(前端,后台)