SpringMVC在多文件上传的时候报Request processing failed; nested exception is org.springframework.beans.BeanInst

报错

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";
		
	}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值