最近项目中页面比较复杂,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. 【转】Chrome 控制台不完全指南

    原文出处: 刘哇勇的博客(@刘哇勇)   欢迎分享原创到伯乐头条 Chrome的开发者工具已经强大到没朋友的地步了,特别是其功能丰富界面友好的console,使用得当可以有如下功效: 更高「逼格」更快 ...

  2. WPF自适应可关闭的TabControl 类似浏览器的标签页

    效果如图: 虽然说是自适应可关闭的TabControl,但TabControl并不需要改动,不如叫自适应可关闭的TabItem. 大体思路:建一个用户控件,继承自TabItem,里面放个按钮,点击的时 ...

  3. 谈谈我的入门级实体框架Loogn.OrmLite

    每次看到有新的ORM的时候,我总会留意一下,因为自己也写过一个这样的框架,人总是有比较之心的.我可能会down下来跑一跑,也可能不会这么做,这个取决于跑起来的难易程度.我是很懒的,有XML配置或其他稍 ...

  4. js的this和面向对象编程

    很奇怪的是很多书或资料没有把这个事情讲清楚. 关键就是在于没有一个整体的思维技术模式,问题被隔离了所以反而不容易理解. 我们先看this,这是js的关键字,指示函数的上下文对象. 这里问题就来了,比如 ...

  5. 建模算法(七)——排队论模型

    (一)基本概念 一.排队过程的一般表示 凡是要求服务的对象称为顾客,凡是为顾客服务的称为服务员 二.排队系统的组成和特征 主要由输入过程.排队规则.服务过程三部分组成 三.排队模型的符号表示 1.X: ...

  6. Android Studio NDK编程-环境搭建及Hello!

    一,下载 安装android-ndk开发包 NDK各个版本链接二,新建项目NDKDemo,选择空Activity就可以:(注:Android studio 2.2,可通过SDK Tools 添加LLD ...

  7. Maven_profile_使用profile配置不同环境的properties(实践)

    配置方法分为以下几个步骤: 1.配置profiles节点(pom.xml) 2.配置build节点(pom.xml)--如果不配置该节点则无法找到profile中的properties属性值,并且配置 ...

  8. [React] 多组件生命周期转换关系

    前段时间一直在基于React做开发,最近得空做一些总结,防止以后踩坑. 言归正传,React生命周期是React组件运行的基础,本文主要是归纳多组件平行.嵌套时,生命周期转换关系. 生命周期 Reac ...

  9. linux系统的学习

    通过<鸟哥的linux私房菜>的学习,自己得到的收获! 关机与重启 shutdown -k now "message" 用以发送所有信息,并不是真的关机.还可以登录新的 ...

  10. lua学习例子

    extern "C"{ #include <lua.h> #include <lauxlib.h> #include <lualib.h> } ...