没有选择附件,但是点击上传按钮的时候会报错。

之前不选择文件,直接上传空文件是可以的,后来不知道改了什么就不行了。

错误信息:

-- :: [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 '的更多相关文章

  1. 【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 ...

  2. 完美解决报错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' 首先这个错误的意思是 前台页面 ...

  3. 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] ...

  4. 前台传参数时间类型不匹配:type 'java.lang.String' to required type 'java.util.Date' for property 'createDate'

    springMVC action接收参数: org.springframework.validation.BindException: org.springframework.validation.B ...

  5. 解决springMVC文件上传报错: The current request is not a multipart request

    转自:https://blog.csdn.net/HaHa_Sir/article/details/79131607 解决springMVC文件上传报错: The current request is ...

  6. 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 ...

  7. 两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错

    遇到了两个由于php.ini配置错误导致的报错:ajax图片上传报错和exec报错 首先第一个: 在做一个用ajax图片上传的功能中,php报了这样一个错误:File upload error - u ...

  8. 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 ...

  9. Spring MVC上传文件

    Spring MVC上传文件 1.Web.xml中加入 <servlet> <servlet-name>springmvc</servlet-name> <s ...

随机推荐

  1. HDOJ 2058 The sum problem

    Problem Description Given a sequence 1,2,3,--N, your job is to calculate all the possible sub-sequen ...

  2. bzoj1208 [HNOI2004]宠物收养所(STL,Treap)

    1208: [HNOI2004]宠物收养所 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 5956  Solved: 2317[Submit][Sta ...

  3. 《University Calculus》-chaper13-多重积分-三重积分的引入

    承接之前对一重积分和二重积分的介绍,这里我们自然的引出三重积分. 在二重积分的引入中,我们曾经埋下过一个小伏笔,二重积分的几何意义是求解一个体积,但是我们仅仅限定在了曲顶柱体的几何体,那么对于完全由曲 ...

  4. 【数学】【NOIp2012】同余方程 题解 以及 关于扩展欧几里得与同余方程

    什么是GCD? GCD是最大公约数的简称(当然理解为我们伟大的党也未尝不可).在开头,我们先下几个定义: ①a|b表示a能整除b(a是b的约数) ②a mod b表示a-[a/b]b([a/b]在Pa ...

  5. Flex3在应用RemoteObject出现问题解决方法

    出现该问题 <mx:RemoteObject id="robj" destination="hello" endpoint="http://lo ...

  6. Oracle中alter system命令参数之scope

    SCOPE The SCOPE clause lets you specify when the change takes effect. Scope depends on whether you s ...

  7. 关于ETL的几种运行

    一:代码部分 1.新建maven项目 2.添加需要的java代码 3.书写mapper类 4.书写runner类 二:运行方式 1.本地运行 2. 3. 三:本地运行方式 1.解压hadoop到本地 ...

  8. Java 获取今天之前的七天 的日期

    package test; import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date; pub ...

  9. 【protobuf进阶】读取proto实体里的extensionObject对象的方法

    //设置扩展对象 ProtoBuf.Extensible.AppendValue //读取扩展对象 ProtoBuf.Extensible.GetValue 最近通过C#的TcpClient调用jav ...

  10. [AngularJS] ng-if vs ng-show

    ng-show: ng-show element will stay in dom, just added a ng-hide attr, so it won't show. ng-if: It ha ...