国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Java > 正文

Java上傳文件錯誤java.lang.NoSuchMethodException的解決辦法

2024-07-14 08:43:30
字體:
來源:轉載
供稿:網友

錯誤詳情:

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;  }

記錄錯誤。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對VeVb武林網的支持。


注:相關教程知識閱讀請移步到JAVA教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 周口市| 建昌县| 屏东县| 岫岩| 韩城市| 巫山县| 会同县| 长汀县| 利川市| 湖州市| 铜川市| 饶河县| 邛崃市| 安乡县| 昭苏县| 麦盖提县| 临夏市| 台中市| 汕头市| 修水县| 涟水县| 措美县| 蕉岭县| 突泉县| 丰县| 深州市| 万安县| 商城县| 星座| 射阳县| 杭锦旗| 沿河| 兴仁县| 玛沁县| 上犹县| 永寿县| 海晏县| 崇信县| 云浮市| 岗巴县| 麟游县|