一、包装类型POJO绑定

什么是包装类型:多个POJO类型的组合

如:一个学生(Students)所在的班级(Classes)中各科(Source)成绩(Score),可能会涉及到多个POJO这样,就需要使用包装类型的POJO

代码:

StudentsQueryVo{
    private Students stutent;
    private Classes class;
    private Source source;
    private Score score;
}

具体用法:

1、定义一个包装类型POJO

public class ItemsQueryVo {
    //为了系统 可扩展性,对原始生成的po进行扩展
    private ItemsCustom itemsCustom;

2、页面定义

商品名称:<input name="itemsCustom.name" />

3、controller

public ModelAndView queryItems(ItemsQueryVo itemsQueryVo) throws Exception

二、集合类型绑定

  Ⅰ、数组类型

    ①、页面定义

<c:forEach items="${itemsList }" var="item">
<tr>    
    <td><input type="checkbox" name="items_id" value="${item.id}"/></td>
    <td>${item.name }</td>
    <td>${item.price }</td>
    <td><fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
    <td>${item.detail }</td>
    
    <td><a href="${pageContext.request.contextPath }/items/editItems.action?id=${item.id}">修改</a></td>

</tr>
</c:forEach>

    ②、controller方法:

    // 批量删除 商品信息
    @RequestMapping("/deleteItems")
    public String deleteItems(Integer[] items_id) throws Exception {

  Ⅱ、List参数绑定

    ①、包装类型
      使用List接收页面提交的批量数据,通过包装pojo接收,在包装pojo中定义list<pojo>属性

public class ItemsQueryVo {
    
    //为了系统 可扩展性,对原始生成的po进行扩展
    private ItemsCustom itemsCustom;
    
    //批量商品信息
    private List<ItemsCustom> itemsList;

    ②、页面定义

 

<c:forEach items="${itemsList }" var="item" varStatus="status">
<tr>    

    <td><input name="itemsList[${status.index }].name" value="${item.name }"/></td>
    <td><input name="itemsList[${status.index }].price" value="${item.price }"/></td>
    <td><input name="itemsList[${status.index }].createtime" value="<fmt:formatDate value="${item.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/>"/></td>
    <td><input name="itemsList[${status.index }].detail" value="${item.detail }"/></td>
</tr>
</c:forEach>

    ③、controller方法

    // 批量修改商品提交
    // 通过ItemsQueryVo接收批量提交的商品信息,将商品信息存储到itemsQueryVo中itemsList属性中。
    @RequestMapping("/editItemsAllSubmit")
    public String editItemsAllSubmit(ItemsQueryVo itemsQueryVo)
            throws Exception {

  Ⅲ、map参数绑定

    ①、定义包装类

private Map<String, Object> itemInfo = new HashMap<String, Object>();

    ②、页面定义

姓名:<inputtype="text"name="itemInfo['name']"/>
年龄:<inputtype="text"name="itemInfo['price']"/>

    ③、controller方法

public String xxxsubmit(QueryVo queryVo)throws Exception{