报错
Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [[Lorg.springframework.web.multipart.MultipartFile;]: No default constructor found; nested exception is java.lang.NoSuchMethodException: [Lorg.springframework.web.multipart.MultipartFile;.<init>()
解决办法
忘记加注解, @RequestParam(“photo”) 记得加
//添加多个图片
@RequestMapping("/add_file")
public String upload(AdminInfo admin, @RequestParam("photo") MultipartFile photo[],HttpServletRequest request) throws IllegalStateException, IOException {
//如果没有选择文件,就不要进行上传操作
for(int i = 0 ; i < photo.length ; i++) {
if(photo[i].getSize() != 0) {
System.out.println("文件名getOriginalFilename"+photo[i].getOriginalFilename());
System.out.println("上传控件的名称getName"+photo[i].getName());
System.out.println("文件大小getSize"+photo[i].getSize());
System.out.println("文件的mine类型 getContentType"+photo[i].getContentType());
String path = request.getServletContext().getRealPath("/upload-files");
String fileName = photo[i].getOriginalFilename();
File fileDest = new File(path,fileName);//路径
photo[i].transferTo(fileDest);
System.out.println(admin);
}
}
request.setAttribute("msg", "图片上传成功");
return "forward:/File-upload.jsp";
}