填入数据,批量更新;
提交的表单:
<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
原文地址:https://blog.csdn.net/m15517986455/article/details/79543546