SpringMVC第九篇——使用集合接收参数(批量提交)

本文介绍了如何在SpringMVC中使用集合接收参数,实现批量更新操作。通过创建POJO和包装类,配合Controller接收,成功从表单中获取并打印出数据,展示了批量提交的实现过程。
摘要由CSDN通过智能技术生成

这里写图片描述

填入数据,批量更新;

提交的表单:

<form action="abc"  method="post">
1<input type="checkbox"  name="id"  value="1" >
高度<input type="text"    name="toollist[0].height" >
长度<input type="text"    name="toollist[0].width" ><br>
2<input type="checkbox"  name="id" value="2" >
高度<input type="text"    name="toollist[1].height" >
长度<input type="text"    name="toollist[1].width" ><br>
3<input type="checkbox"  name="id"   value="3"  >
高度<input type="text"    name="toollist[2].height" >
长度<input type="text"    name="toollist[2].width" ><br>
4<input type="checkbox"  name="id"   value="4" >
高度<input type="text"    name="height" >
长度<input type="text"    name="width" ><br>
5<input type="checkbox"  name="id" value="5" >
高度<input type="text"    name="height" >
长度<input type="text"    name="width" ><br>
<button  type="submit">更新</button>
</form>

POJO:

public class Tool {
private Integer id;
private String height;
private String width;
。。。省略getter,setter,toString方法

包装类:

public class QueryVo {
       private Integer [] id;
       private Tool tool;
       private List<Tool> toollist;
。。。省略getter,setter,toString方法

controller接收:

@RequestMapping(value = "/abc")
       public  ModelAndView itemList(String [] id,QueryVo vo){

       System.out.println(vo.getToollist().toString());
       System.out.println(Arrays.toString(vo.getId()));

            // ModelAndView ma=new ModelAndView();
            // ma.setViewName("/hello.jsp");
        return ma;

       }
点击控制台打印出:

这里写图片描述

总结:

使用了包装类,包装类的属性,就是pojo,ids,list,表示对象,选中的ids,和提交的list集合,(元素是pojo,)
页面提交的name值就是每一个pojo的属性值。
如果页面使用了循环标签:

<c:forEach items="${itemList }" var="item" varStatus="s">
<tr>   
<td><input type="text" name="toollist [${s.index}].width"
</tr>
</c:forEach>

${status.index}    输出行号,从0开始。
${status.count}    输出行号,从1开始。

返回 SpringMVC的学习笔记目录

http://blog.csdn.net/m15517986455/article/details/79319601

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值