【FAQ】SpingMVC实现集合參数(Could not instantiate bean class [java.util.List])
需求,要求批量新增或者改动一个List,在Spring MVC中是不支持以下代码的写法
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(List<ProductCollocation> productCollocations ,HttpServletRequest request, RedirectAttributes redirectAttributes) {
for (ProductCollocation productCollocation : productCollocations) {
productCollocation.setModifyDate(DateUtil.getDate());
productCollocationService.update(productCollocation, "create_date","product","collocation","description");
}
addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
return "redirect:list.jhtml";
}
会抛出异常
nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]:
是否事实上也非常easy,Spring MVC 须要支持Form表单对象的方式映射,使用get set器来填充对象。
新增一个Form
public class ProductCollocationForm {
List<ProductCollocation> productCollocations; /**
* @return the productCollocations
*/
public List<ProductCollocation> getProductCollocations() {
return productCollocations;
} /**
* @param productCollocations the productCollocations to set
*/
public void setProductCollocations(List<ProductCollocation> productCollocations) {
this.productCollocations = productCollocations;
}
}
再使用Form来set对象
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String update(ProductCollocationForm productCollocationForm ,HttpServletRequest request, RedirectAttributes redirectAttributes) {
for (ProductCollocation productCollocation : productCollocationForm.getProductCollocations()) {
productCollocation.setModifyDate(DateUtil.getDate());
productCollocationService.update(productCollocation, "create_date","product","collocation","description");
}
addFlashMessage(redirectAttributes, SUCCESS_MESSAGE);
return "redirect:list.jhtml";
}
前台就能够使用索引的方式对后台对象设置值了
<td>
<input type="text" name="productCollocations[${productCollocation_index}].displayName" class="text" maxlength="200" style="width:100px" value="${productCollocation.displayName}"/>
<input type="hidden" name="productCollocations[${productCollocation_index}].id" class="text" maxlength="200" value="${productCollocation.id}"/>
</td>
【FAQ】SpingMVC实现集合參数(Could not instantiate bean class [java.util.List])的更多相关文章
- SpingMVC实现集合参数(Could not instantiate bean class [java.util.List])
需求,要求批量新增或者修改一个List,在springMVC中是不支持下面代码的写法: @RequestMapping(value = "/update", method = Re ...
- 集合框架的类和接口均在java.util包中。 任何对象加入集合类后,自动转变为Object类型,所以在取出的时候,需要进行强制类型转换。
集合框架的类和接口均在java.util包中. 任何对象加入集合类后,自动转变为Object类型,所以在取出的时候,需要进行强制类型转换.
- springmvc学习笔记(13)-springmvc注解开发之集合类型參数绑定
springmvc学习笔记(13)-springmvc注解开发之集合类型參数绑定 标签: springmvc springmvc学习笔记13-springmvc注解开发之集合类型參数绑定 数组绑定 需 ...
- EM算法求高斯混合模型參数预计——Python实现
EM算法一般表述: 当有部分数据缺失或者无法观察到时,EM算法提供了一个高效的迭代程序用来计算这些数据的最大似然预计.在每一步迭代分为两个步骤:期望(Expectation)步骤和最大化( ...
- grep命令经常使用參数及使用方法
1.grep介绍 grep命令是Linux系统中一种强大的文本搜索工具,它能使用正則表達式搜索文本.并把匹 配的行打印出来.grep全称Global Regular Expression Print, ...
- 增强for循环、Map接口遍历、可变參数方法
增强for循环 1.for循环能做得事情.增强for循环大部分都能做(假设要想获得下标的时候就必须使用简单for循环了) 2.增强for有时候可以方便的处理集合遍历的问题,可是集合的标准遍历是使用迭代 ...
- matplotlib画图实例:pyplot、pylab模块及作图參数
http://blog.csdn.net/pipisorry/article/details/40005163 Matplotlib.pyplot画图实例 {使用pyplot模块} matplotli ...
- pthread_create()创建线程时传入多个參数
因为接口仅仅定义了一个入參void *arg int pthread_create(pthread_t *tidp,const pthread_attr_t *attr, (void*)(*start ...
- 关于mybatis中,批量增删改查以及參数传递的问题
1.參数传递的问题 大多数情况下,我们都是利用map作为參数,而且大部分情况下都是仅仅有一个參数. 可是,我们也能够利用@param注解,来传入多个參数,此时,mybatis会自己主动将參数封装成ma ...
随机推荐
- centOS下恢复win8引导
正题(非原创): shutdown两次以后确信我的win8引导没有了 百度后找到一个修改grub.cfg文件的方法 这个文件在普通用户下是没有修改的权利的 要在sudo su之后用root权限 vi ...
- 复习知识点:GCD多线程
GCD的基础 #pragma mark - 使用GCD 创建一个 串行 队列 // 第一种:系统提供的创建串行队列的方法 // 在真正的开发中如果需要创建串行队列,比较习惯用这种 // dispatc ...
- zzuli生化危机(dfs)
生化危机 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 73 Solved: 21SubmitStatusWeb Board Description ...
- [HDU 1428]--漫步校园(记忆化搜索)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1428 漫步校园 Time Limit: 2000/1000 MS (Java/Others) M ...
- javascript面向对象创建高级 Web 应用程序
目录 JavaScript 对象是词典 JavaScript 函数是最棒的 构造函数而不是类 原型 静态属性和方法 闭包 模拟私有属性 从类继承 模拟命名空间 应当这样编写 JavaScript ...
- 同步fifo的verilogHDL设计实例
原创 设计一个fifo,输入16bit,输出16bit的data,寻址宽度5bit,有空满标志. top 层如下所示: /* date : 2014/10/14 version : modelsim ...
- Python 2.7 学习笔记 访问mysql数据库
一.基本概念 使用python操作数据库,其基本的流程如下(其实所有开发语言访问数据库的流程都是这样). 1.第一,引入相应数据库的python数据库接口模块,针对不同的数据库类型,有不同的数据库访问 ...
- YII 路由配置
伪静态,通过设置server服务,做域名地址的转换工作. urlManager地址美化,通过程序的方式实现地址美化工作. 通过在主配置文件里配置组件来实现: 'components'=>arra ...
- linux stat系统调用,获取文件信息。
stat 函数原型: int stat(const char *path, struct stat *buf); struct stat 说明 struct stat { mode_t st_mode ...
- iOS插件化研究之中的一个——JavaScriptCore
原文:p=191">http://chentoo.com/?p=191 一.前言 一样的开篇问题,为什么要研究这个?iOS为什么要插件化?为什么要借助其它语言比方html5 js甚至脚 ...