最近项目中页面比较复杂,springMVC传参过程中遇到这样一个错误:Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause

经研究发现这是参数封装出了问题。

还原代码:

@RequestMapping("/test")
public ModelAndView test(List<OptionVo> ov){
ModelAndView view = new ModelAndView("list");
return view;
}

VO对象:

public class OptionVo {

	private String name;
private String options;
private List<String> option; public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public String getOptions() {
return options;
} public void setOptions(String options) {
this.options = options;
} public List<String> getOption() {
return option;
} public void setOption(List<String> option) {
this.option = option;
}
}

  可以看出,controller中参数List内封装的不是基本数据类型,而是一个对象,springMVC源码获取前台的参数是:request.getParameter("")来接收参数的,这样的话,封装参数时就出问题了。

解决办法:

将VO对象再进行封装:

public class Form {
private List<OptionVo> o; public List<OptionVo> getO() {
return o;
} public void setO(List<OptionVo> o) {
this.o = o;
}
}

controller:

@RequestMapping("/test")
public ModelAndView test(Form formm){
ModelAndView view = new ModelAndView("list");
return view;
}

前台页面:

<input type="text" name="o[0].name" value="爱好">
<input type="text" name="o[0].options" value="爱好">
<input type="hidden" name="o[0].option" value="1">
<input type="hidden" name="o[0].option" value="2">
<input type="hidden" name="o[0].option" value="3">
<input type="hidden" name="o[0].option" value="4">
<hr>
<input type="text" name="o[1].name" value="哈哈">
<input type="text" name="o[1].options" value="爱好2">
<input type="hidden" name="o[1].option" value="1">
<input type="hidden" name="o[1].option" value="2">
<input type="hidden" name="o[1].option" value="3">
<input type="hidden" name="o[1].option" value="4">
<hr>

Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause的更多相关文章

  1. 【FAQ】SpingMVC实现集合參数(Could not instantiate bean class [java.util.List])

    需求,要求批量新增或者改动一个List,在Spring MVC中是不支持以下代码的写法 @RequestMapping(value = "/update", method = Re ...

  2. SpingMVC实现集合参数(Could not instantiate bean class [java.util.List])

    需求,要求批量新增或者修改一个List,在springMVC中是不支持下面代码的写法: @RequestMapping(value = "/update", method = Re ...

  3. org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class

    错误:org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util ...

  4. Failed to instantiate [java.util.List]: Specified class is an interface

    错误信息提示: Failed to instantiate [java.util.List]: Specified class is an interface; 错误信息意思:参数错误,参数封装出了问 ...

  5. 【spring mvc】后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface

    后台spring mvc接收List参数报错如下:org.springframework.beans.BeanInstantiationException: Failed to instantiate ...

  6. jdk8中java.util.concurrent包分析

    并发框架分类 1. Executor相关类 Interfaces. Executor is a simple standardized interface for defining custom th ...

  7. Java Concurrency - java.util.concurrent API Class Diagram

    摘自: www.uml-diagrams.org Here we provide several UML class diagrams for the Java™ 7 java.util.concur ...

  8. java.util.LinkedHashMap cannot be cast to xxx 和 net.sf.ezmorph.bean.MorphDynaBean cannot be cast to xxx

    java.util.LinkedHashMap cannot be cast to com.entity.Person 使用mybatis, resultMap映射的是实体类Person, 查询出来的 ...

  9. 2019-8-26 LinkedHashMap 转 List [java.util.LinkedHashMap cannot be cast to com.zq.dataservice.bean.Index]

    java.util.LinkedHashMap cannot be cast to com.zq.dataservice.bean.Index 上述错误是在做一个趋势投资demo时遇到的. 说的是链式 ...

随机推荐

  1. Oracle系列——开发中奇葩问题你遇到几个(一)

    前言:在使用oracle数据进行开发的时候有没有经常出现一些很奇怪.很纳闷.很无厘头的问题呢.下面是本人使用oracle一段时间遇到的问题小节,在此做个记录,方便以后再遇到类似的问题能快速解决.如果你 ...

  2. cookie学习指南

    一.什么是cookie cookie也叫HTTP cookie,最初是用来客户端和服务器端进行会话用的,由于HTTP是一种无状态的协议,为了维持用户和跟踪用户信息,所以引入了cookie和sessio ...

  3. CSS基本知识1-CSS基本概念

    CSS基本概念: 选择器{属性:值;属性:值} CSS继承:子元素继承父元素样式,父子关系看DOM结构. CSS覆盖: 浏览器缺省设置 外部样式表 内部样式表(位于 <head> 标签内部 ...

  4. DayPilot 7.9.3373 去掉DEMO

    更新升级倒是蛮快的,多了Gantt图,此处下载先: http://files.cnblogs.com/files/pccai/DayPilot_2.0_4.0_7.9.3373.rar

  5. ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法

    ORACLE 中的 ROW_NUMBER() OVER() 分析函数的用法 ROW_NUMBER() OVER(partition by col1 order by col2) 表示根据col1分组, ...

  6. ReactNative 适合初学的第一个教程demo,找租房

    1.下载工程 我看来看去,最让人容易入门的是这个demo: https://github.com/rayshen/PropertyFinder 是英国某开发者做的搜租房的小demo,包含的知识有:图片 ...

  7. supervisord安装使用简记

    What is supervisor Supervisor is a client/server system that allows its users to monitor and control ...

  8. 有用的git建议

    这篇文章的目的是给经常使用git管理项目提供一个有益的提醒.如果你是git新手,可以先阅读文后的引用部分,然后在回头阅读此篇文章.在介绍git命令之前,你可以先看看来自 on-my-zsh 提供的别名 ...

  9. java--HashMap多线程并发问题分析

    并发问题的症状 多线程put后可能导致get死循环 从前我们的Java代码因为一些原因使用了HashMap这个东西,但是当时的程序是单线程的,一切都没有问题.后来,我们的程序性能有问题,所以需要变成多 ...

  10. <<< php程序在运行后报“internal server error”错误

    上传的php程序在运行后报“internal server error”错误,检查以下两方面: 1.请您检查php程序的属性是否设置为755,如果php程序的属性不是755,那么运行的时候会报“int ...