最近项目中页面比较复杂,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. ZigZag Conversion leetcode java

    题目: The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows l ...

  2. .NET Core 1.0 RC2 历险之旅

    文章背景:对于.NET Core大家应该并不陌生, 从它被 宣布 到现在已经有1-2年的时间了,其比较重要的一个版本1.0 RC2 也即将发布..Net Core从一个一个的测试版到现在的RC2,经历 ...

  3. JavaScript零基础学习系列三

    函数 函数:为了完成某个功能而定义的代码的集体.函数是数据类型,只读的对象:函数也是对象:代码的重用.(JavaScript中) 定义语法:function 函数名(形式参数1,形式参数2--){ / ...

  4. BZOJ 3926: [Zjoi2015]诸神眷顾的幻想乡

    3926: [Zjoi2015]诸神眷顾的幻想乡 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1017  Solved: 599[Submit][S ...

  5. JQuery slidebox实现图片轮播

    jQuery图片轮播(焦点图)插件jquery.slideBox,简单设置下参数就可以多个多种动画效果,左右,上下,速度,还可指定默认显示第N张,点击的按钮在现代浏览中可以实现圆形或圆角效果,插件代码 ...

  6. 加载dll过程中assembly失败

    错误现象: 进行插件读取时出现错误:“尝试从一个网络位置加载程序集,在早期版本的 .NET Framework 中,这会导致对该程序集进行沙盒处理.此发行版的 .NET Framework 默认情况下 ...

  7. Sublime Text 2 实用快捷键(Mac OS X)

    打开/前往: ⌘T 前往文件 ⌘⌃P 前往项目 ⌘R 前往 method ⌘⇧P 命令提示 ⌃G 前往行 ⌃ ` python 控制台 ——————— 编辑: ⌘L 选择行 (重复按下将下一行加入选择 ...

  8. java分析源码-ReentrantLock

    一.前言 在分析了 AbstractQueuedSynchronier 源码后,接着分析ReentrantLock源码,其实在 AbstractQueuedSynchronizer 的分析中,已经提到 ...

  9. Node实践之二

    先从一个简单的demo说起,用cmd打开命令提示符,输入echo Hello,大家是不是看到终端上显示出了Hello字样,事实上这就是一个简单的事件. 回到正题,相信提到node.js,免不了让人想起 ...

  10. Math类

    Math类:用于执行基本数学运算的方法 方法: public static int abs(int a):绝对值 public static double ceil(double a):向上取整   ...