首页 新闻 搜索 专区 学院

导入execl时报错:Cannot convert value of type [java.util.LinkedList] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found

0
悬赏园豆:20 [待解决问题]

在当前页面中存在一个或多个导入按钮,在给第一个按钮导入execl文档时没有问题,在给第二个按钮导入execl时就会抛异常:

spring配置文件<aop:config>中存在: proxy-target-class="true"

java代码:

@RequestMapping(value = "/ComplexUpload",method={RequestMethod.GET,RequestMethod.POST})
    @ResponseBody
    public Object importExcel(@RequestParam(value = "file",required = false)final MultipartFile file,final HttpServletRequest request,final HttpServletResponse response) throws HbcsoftException{
        JSONObject jsonObject = new JSONObject();
        String message = "";
        try{
            MultipartResolver resolver = new CommonsMultipartResolver(request.getSession().getServletContext());
            MultipartHttpServletRequest multipartRequest = resolver.resolveMultipart(request);
            InputStream in =null;  
            List<List<Object>> listob = null;
            MultipartFile filem = multipartRequest.getFile("file");  
            if(file.isEmpty()){  
                throw new Exception("文件不存在!");
            }  
            in = file.getInputStream();  
            jsonObject = new ImportExcelUtil().getBankListByExcel(in,file.getOriginalFilename());
        }catch(Exception e){
            message = "导入文件出现问题,请检查文件有效性";
            throw new HbcsoftException("",ErrorConstant.ERROR_CODE , e);
        }
        return jsonObject;
    }

 

异常内容:

org.springframework.beans.ConversionNotSupportedException: Failed to convert value of type 'java.util.LinkedList' to required type 'org.springframework.web.multipart.MultipartFile'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.LinkedList] to required type [org.springframework.web.multipart.MultipartFile]: no matching editors or conversion strategy found
    at org.springframework.beans.TypeConverterSupport.doConvert(TypeConverterSupport.java:74)
    at org.springframework.beans.TypeConverterSupport.convertIfNecessary(TypeConverterSupport.java:47)
    at org.springframework.validation.DataBinder.convertIfNecessary(DataBinder.java:603)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveRequestParam(HandlerMethodInvoker.java:515)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:348)
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
    at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at com.hbcsoft.sys.controller.UserFilter.doFilter(UserFilter.java:69)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

ζั͡ޓއއއ๓ 堕落的主页 ζั͡ޓއއއ๓ 堕落 | 初学一级 | 园豆:5
提问于:2017-04-27 20:34
< >
分享
所有回答(1)
0

检查下form表单属性是否写上enctype="multipart/form-data"

2012 | 园豆:19634 (专家六级) | 2017-04-28 08:01

http://stackoverflow.com/questions/36250863/cannot-convert-value-of-type-java-lang-string-to-required-type-org-springfram 

支持(0) 反对(0) 2012 | 园豆:19634 (专家六级) | 2017-04-28 08:01

导入用的是同一个form标签,enctype是存在的,难道是不能使用公用的form表单?

清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册