没有合适的资源?快使用搜索试试~ 我知道了~
Java上传文件错误java.lang.NoSuchMethodException的解决办法
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
6 下载量 122 浏览量
2020-08-26
12:07:29
上传
评论 1
收藏 42KB PDF 举报
温馨提示
试读
2页
今天小编就为大家分享一篇关于Java上传文件错误java.lang.NoSuchMethodException的解决办法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
资源详情
资源评论
资源推荐
Java上传文件错误上传文件错误java.lang.NoSuchMethodException的解决办的解决办
法法
今天小编就为大家分享一篇关于Java上传文件错误java.lang.NoSuchMethodException的解决办法,小编觉得内容挺不
错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
错误详情:错误详情:
java.lang.NoSuchMethodException: [Lorg.springframework.web.multipart.MultipartFile;.<init>()
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.method.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<String,Object> uploadFilesForWEditor(@RequestParam("files")MultipartFile[] files,HttpServletRequest request,HttpServletResponse response){
Map<String,Object> map=new HashMap<>();
List<String> url = new ArrayList<>();
for (int i = 0; i < files.length; i++) {
String result=FileUploadUtils.fileUpload(files[i], request, response);
if(result!=""){
url.add(result);
}
}
if(url.size()>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;
}
记录错误。
总结总结
weixin_38522029
- 粉丝: 4
- 资源: 880
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于protel99se(原理图库+封装库)电路设计硬件PCB设计protel库合集protel封装大全(近3000个).zip
- python-leetcode面试题解之第157题用Read4读取N个字符-题解.zip
- python-leetcode面试题解之第156题上下翻转二叉树-题解.zip
- python-leetcode面试题解之第155题最小栈-题解.zip
- python-leetcode面试题解之第153题寻找旋转排序数组中的最小值-题解.zip
- python-leetcode面试题解之第152题乘积最大子数组-题解.zip
- python-leetcode面试题解之第151题反转字符串中的单词-题解.zip
- python-leetcode面试题解之第150题逆波兰表达式求值-题解.zip
- python-leetcode面试题解之第149题直线上最多的点数-题解.zip
- python-leetcode面试题解之第148题排序链表-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0