最近项目中页面比较复杂,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. cocoa框架 for iOS

    1.Cocoa是什么? Cocoa是OS X和 iOS操作系统的程序的运行环境. 是什么因素使一个程序成为Cocoa程序呢?不是编程语言,因为在Cocoa开发中你可以使用各种语言:也不是开发工具,你可 ...

  2. AppBox升级进行时 - 如何向OrderBy传递字符串参数(Entity Framework)

    AppBox 是基于 FineUI 的通用权限管理框架,包括用户管理.职称管理.部门管理.角色管理.角色权限管理等模块. Entity Framework提供的排序功能 再来回顾一下上篇文章,加载用户 ...

  3. HashMap遍历的两种方式

    第一种: Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) {    ...

  4. struts2报错:There is no Action mapped for namespace [/] and action name [userAction!add]

    使用struts2.3进行动态方法调用时出现: There is no Action mapped for namespace [/user] and action name [user!add] a ...

  5. iOS地图 -- 区域监听的实现和小练习

    区域监听用到的方法 [self.mgr startMonitoringForRegion:region]; --> 开启区域监听,没有返回值,在代理方法中得到信息并且处理信息 注:该方法只有用户 ...

  6. java/python中的队列

    Queue<TreeNode> que=new LinkedList<>(); 用linkedlist实现队列,offer,poll进出队列,peek对列顶部元素 python ...

  7. 线段树 HDU 3308

    t 题目大意:给你n个数,m个操作.操作有两种:1.U x y 将数组第x位变为y   2. Q x y 问数组第x位到第y位连续最长子序列的长度.对于每次询问,输出一个答案 #include< ...

  8. delphi 默认值

    只有全局变量才可以赋初值 i:integer=0;

  9. 数据结构图文解析之:哈夫曼树与哈夫曼编码详解及C++模板实现

    0. 数据结构图文解析系列 数据结构系列文章 数据结构图文解析之:数组.单链表.双链表介绍及C++模板实现 数据结构图文解析之:栈的简介及C++模板实现 数据结构图文解析之:队列详解与C++模板实现 ...

  10. phpexcel导入数据提示失败

    phpexcel导入excel时明明只有几行数据,却提示506行失败,原来是excel中有506行"无效数据"(看起来是空的,但是和没有数据不一样).