[Ljava.lang.Object;]: No default constructor found

  • Servlet.service() for servlet [springmvc] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate **[[Ljava.lang.Object;]: No default constructor found; **nested exception is java.lang.NoSuchMethodException: [Ljava.lang.Object;.()] with root cause
    java.lang.NoSuchMethodException: [Ljava.lang.Object;.()

    我在做一个网站开发,我希望在Cotroller层中传入Object类型的可变参数,就一直报这个错误,请问该怎么解决呢?以下是我的代码:

    //可变参数做查询
        //localhost/detailsss/?detail=徐国权&detail=12
        @RequestMapping("/detailsss/")
        public String queryDetails(Model model,Object...detail){
    
            try {
                Object consume = null;
                List<Object> list = new ArrayList<>();
                for(Object obj : detail){   
                    if(obj instanceof String){                  
                        consume = new String(((String) obj).getBytes("iso-8859-1"),"utf-8");
                    }
                    else if(obj instanceof Integer){
                        consume = (int)obj;
                    }
                    else if(obj instanceof Date){
                        consume = (Date)obj;
                    }
                    else if(obj instanceof Time){
                        consume = (Time)obj;
                    }else{
                        consume = obj;
                    }
                    list.add(consume);
                }
                //调用service的方法
                List<Detailed> details = comsumeService.queryDetails(list);
                model.addAttribute("details",details);
                return "comsume_info";
            } catch (Exception e) {
                e.printStackTrace();
                return "err";
            }       
        }



HUX布斯
浏览 1641回答 4
4回答

Helenr

Object类不能直接实例化,直接用string类型呗,跟object不是一样嘛

翻翻过去那场雪

debug看看其他层哪里有问题,这里贴上的代码应该没问题
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java