Java上传文件错误Java.lang.nosuchmethodexception的解决方案
发布到2020-3-24|
复制链接
共享Java.lang.nosuchmethodexception对Java上载文件的解决方案。 小恶魔觉得内容很好。 现在分享给大家,非常有参考价值。 有需要的朋友一起跟着小恶魔看看吧
错误详细信息:
` ` ` java
Java.lang.nosuchmethodexception : [ lorg.spring framework.web.multipart.multipart file;() ) ) )。
at Java.lang.class.get constructor0(unknown source ) )。
at Java.lang.class.getdeclaredconstructor (未知源) )。
atorg.spring framework.beans.beanutils.instantiate class (beanutils.Java :104 )。
atorg.spring framework.web.method.annotation.modelattributemethodprocessor.create attribute (
atorg.spring framework.web.servlet.MVC.method.annotation.servletmodelattributemethodprocessor.create atribute (属性
``````
解决方案:使用wangEditor设置多个文件的上载时,会出现对方法进行参数注释的错误@RequestParam。 上传单个文件没有这个问题。 直接使用多个文件上传时发生错误,使用了单个文件循环。 代码如下。
` ` ` java
@ request mapping (value=' uploadfilesforweditor ',method={RequestMethod.GET,RequestMethod.POST} )
@响应主体
publicstaticmapuploadfilesforweditor (@ request param (' files ) ) files,HttpServletRequest request,http
Map map=new HashMap (;
List url=new ArrayList (;
for(intI=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 );
}
返回图;
}
``````
文件上载实用程序:
` ` ` java
publicstaticstringfileupload (多参数文件,http服务器请求请求,http服务器响应) {
//获取图像的原始名称
string old name=file.getoriginalfilename (;
stringtimename=system.current time millis () ' _ ';
String newName=timeName oldName;
//获取项目路径并在项目路径下创建新文件夹
String path='D:/uploadFile ';
//新建uploadFile文件夹
文件父路径=new file (路径;
if (! parentPath.exists (
parentPath.mkdirs (;
}
String src=' ';
try {
file.transferto (新文件(parent path,newName ) );
file the file=new file (parent path '/' newname );
if(thefile.exists () ) )。
//将连接图像的相对路径设为URL
src='/' newName;
}else{
src=' ';
}
}catch(illegalstateexceptione ) )
e .打印堆栈跟踪(;
}catch(ioexceptione ) {
e .打印堆栈跟踪(;
}
返回src;
}
``````