解决spring mvc 上传报错,Field [] isn't an enum value,Failed to convert value of type 'java.lang.String[]' to required type '
没有选择附件,但是点击上传按钮的时候会报错。
之前不选择文件,直接上传空文件是可以的,后来不知道改了什么就不行了。
错误信息:
-- :: [http--] TRACE org.springframework.beans.TypeConverterDelegate - Field [] isn't an enum value
java.lang.NoSuchFieldException:
at java.lang.Class.getField(Unknown Source)
at org.springframework.beans.TypeConverterDelegate.attemptToConvertStringToEnum(TypeConverterDelegate.java:)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:)
at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:)
省略一部分…………
at java.lang.Thread.run(Unknown Source)
-- :: [http--] TRACE org.springframework.web.method.HandlerMethod - Error resolving argument [] [type=[Lorg.springframework.web.multipart.MultipartFile;]
HandlerMethod details:
Controller [com.cvicin.ssm.sys.fileUpload.FileUploadClass]
Method [public java.lang.String com.cvicin.ssm.sys.fileUpload.FileUploadClass.hotProductFinance_fileUpload(java.lang.String,java.lang.String,org.springframework.web.multipart.MultipartFile[],javax.servlet.http.HttpServletRequest)] org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.lang.String[]' to required type 'org.springframework.web.multipart.MultipartFile[]'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:)
at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:)
at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:)
省略一部分…………
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:)
at org.springframework.beans.TypeConverterDelegate.convertToTypedArray(TypeConverterDelegate.java:)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:)
at org.springframework.beans.SimpleTypeConverter.convertIfNecessary(SimpleTypeConverter.java:)
... more
解决办法:在上传之前判断有没有附件,没有的话就不执行了上传事件了。
页面代码:
<form id="saveFile" method="post" enctype="multipart/form-data">
<div>上传新的附件:</div>
<div>
<input type="file" name="file" />
<input type="file" name="file" />
<input type="file" name="file" />
<input type="file" name="file" />
<input type="file" name="file" />
</div>
</form>
js代码:
var fileFlag = false;
$("input[name=file]").each(function(){
if($(this).val()!="") {
fileFlag = true;
return false;
}
});
if(fileFlag) {
var url = "${pageContext.request.contextPath}/fileUpload/fileUpload";
$("#saveFile").ajaxSubmit({//执行上传
url:url,
success:function(msg){
//
}
});
}
其实就是jquery选择器,遍历name = file是不是空值。
记下了,省的以后忘了。。。 o(╯□╰)o
解决spring mvc 上传报错,Field [] isn't an enum value,Failed to convert value of type 'java.lang.String[]' to required type '的更多相关文章
- 【spring mvc】后台API查询接口,get请求,后台Date字段接收前台String类型的时间,报错default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'createDate';
后台API查询接口,get请求,后台Date字段接收前台String类型的时间筛选条件 后台接口接收 使用的实体 而createDate字段在后台实体中是Date类型 报错信息: org.spring ...
- 完美解决报错Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'
Failed to convert value of type 'java.lang.String' to required type 'java.util.Date' 首先这个错误的意思是 前台页面 ...
- spring mvc出现 Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'endtime'
在使用spring mvc中,绑定页面传递时间字符串数据给Date类型是出错: Failed to convert property value of type [java.lang.String] ...
- 前台传参数时间类型不匹配:type 'java.lang.String' to required type 'java.util.Date' for property 'createDate'
springMVC action接收参数: org.springframework.validation.BindException: org.springframework.validation.B ...
- 解决springMVC文件上传报错: The current request is not a multipart request
转自:https://blog.csdn.net/HaHa_Sir/article/details/79131607 解决springMVC文件上传报错: The current request is ...
- Failed to convert from type [java.lang.String] to type [java.util.Date] for value '2020-02-06'; nested exception is java.lang.IllegalArgumentException]解决
今天做springbook项目前端输入日期传到数据库保存报了一下错误 Whitelabel Error Page This application has no explicit mapping fo ...
- 两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错
遇到了两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错 首先第一个: 在做一个用ajax图片上传的功能中,php报了这样一个错误:File upload error - u ...
- 17-Java-文件上传报错(commons-fileupload包和commons-io包不支持JDK版本:UnsupportedClassVersionError: org/apache/commons/io/IOUtils : Unsupported major.minor version 52.0)
文件上传报错(commons-fileupload包和commons-io包不支持JDK版本) 这个bug可把我弄惨了!!!我代码是想通过写个文件上传,我写的文件上传需要用到commons-fileu ...
- Spring MVC上传文件
Spring MVC上传文件 1.Web.xml中加入 <servlet> <servlet-name>springmvc</servlet-name> <s ...
随机推荐
- Ubuntu 12.04 下安装 Eclipse
方法一:(缺点是安装时附加openjdk等大量程序并无法去除,优点是安装简单) $ sudo apt-get install eclipse 方法二:(优点是安装内容清爽,缺点是配置麻烦)1.安装JD ...
- cf703A Mishka and Game
A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- SRM 395(1-250pt)
DIV1 250pt 题意:在平面直角坐标系中,只能走到整点,每次有两种移动方法,可以沿平行于坐标轴方向走,也可以沿45度方向走,前者走一步耗时wt,后者走一步耗时st.比如从(x, y)可以走到(x ...
- hdu 4632区间 dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4632 用点容斥原理转移状态, dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+ ...
- 理解Android的startservice和bindservice(转)
一.首先,让我们确认下什么是service? service就是android系统中的服务,它有这么几个特点:它无法与用户直接进行交互.它必须由用户或者其他程序显式的启动.它的优先级比较高,它比处于前 ...
- 隐式intent
使用隐式Intent,我们不仅可以启动自己程序内的活动,还可以启动其他程序的活动, 这里我们首先指定了Intent的action是Intent.ACTION_VIEW,这是一个Android系统内置的 ...
- geektool--一款很geek的工具
2016/12/18 今天尝试一款很geek的工具 geektool 听名字就超级geek有木有 get it geektool website 从官网直接下载app,一键傻瓜式安装. use it ...
- 百度云推送的Java实现
推送现在基本APP都有,项目中要通知和消息,所以综合考虑用了百度云推送 Java实现步骤: 1. 下载 http://push.baidu.com/sdk/push_server_sdk_for_ja ...
- 解密-神秘的 RunLoop
引言 一直以来RunLoop就是个神秘的领域,好多2.3年的开发者都不能准确的表述它的作用,说它神秘,其实RunLoop并没有大家想象中的那么神秘,那么不好理解,本文就带大家好好剖析一下”神秘的Run ...
- 在cmd窗口下运行Java程序时无法找到主类的解决办法
我是Java的初学者,昨天在cmd窗口下运行一段Java程序时总是有问题,可以编译但无法执行. 也就是javac时正确,一旦java时就不对了,提示找不到或无法加载主类,经百度谷歌再加上自己的摸索终于 ...