• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Java上传文件错误java.lang.NoSuchMethodException的解决办法

java 搞代码 4年前 (2022-01-05) 88次浏览 已收录 0个评论

今天小编就为大家分享一篇关于Java上传文件错误java.lang.NoSuchMethodException的解决办法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧

错误详情:

 java.lang.NoSuchMethodException: [Lorg.springframework.web.multipart.MultipartFile;.() at java.lang.Class.getConstructor0(Unknown Source) at java.lang.Class.getDeclaredConstructor(Unknown Source) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:104) at org.springframework.web.m<mark style="color:transparent">来源gaodaimacom搞#代%码网</mark>ethod.annotation.ModelAttributeMethodProcessor.createAttribute(ModelAttributeMethodProcessor.java:137) at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.createAttribute(ServletModelAttributeMethodProcessor.java:80)

解决办法:在方法里加上参数注解 @RequestParam

这个错误是在使用wangEditor配置多文件上传的时候出现的,使用单个文件上传没有这个问题。

直接使用多文件上传一直报错,就用了单文件循环。

代码如下:

 @RequestMapping(value="uploadFilesForWEditor",method={RequestMethod.GET,RequestMethod.POST}) @ResponseBody public static Map uploadFilesForWEditor(@RequestParam("files")MultipartFile[] files,HttpServletRequest request,HttpServletResponse response){ Map map=new HashMap(); List url = new ArrayList(); for (int i = 0; i 0){ map.put("errno",0); map.put("msg","上传成功"); map.put("data",url); }else{ map.put("errno",1); map.put("msg","上传失败"); map.put("data",url); } return map; }

FileUploadUtils:

 public static String fileUpload(MultipartFile file,HttpServletRequest request,HttpServletResponse response){ //获取图片的原名字 String oldName=file.getOriginalFilename(); String timeName=System.currentTimeMillis()+"_"; String newName=timeName+oldName; //获取项目的路径 在项目路径下新建文件夹 String path= "D:/uploadFile"; //新建 uploadFile 文件夹 File parentPath=new File(path); if(!parentPath.exists()){ parentPath.mkdirs(); } String src=""; try { file.transferTo(new File(parentPath,newName)); File theFile=new File(parentPath+"/"+newName); if(theFile.exists()){ //拼接图片的相对路径作为URL src="/"+newName; }else{ src=""; } } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return src; }

记录错误。

总结

以上就是Java上传文件错误java.lang.NoSuchMethodException的解决办法的详细内容,更多请关注gaodaima搞代码网其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Java上传文件错误java.lang.NoSuchMethodException的解决办法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址