一、包装类型pojo参数绑定:
需求:商品查询controller方法中实现商品查询条件传入。
实现方法:
1)在形参中 添加HttpServletRequest request参数,通过request接收查询条件参数。
2)在形参中让包装类型的pojo接收查询条件参数。
做法:参数名和包装pojo中的属性一致即可;
(本例中:传递参数 和 ItemsQueryVo属性名itemsCustom一致);
二、数组绑定:
需求:商品批量删除,用户在页面选择多个商品,批量删除。
做法:将页面选择(多选)的商品id,传到controller方法的形参,方法形参使用数组接收页面请求的多个商品id。
(本例中deleteItems(Integer[] item_id) item_id用来接收checkbox的name为item_id数组)
一、二实现如下:
ItemsController:
View Code
ItemsQueryVo:
View Code
查询和批量删除itemsList.jsp:
View Code
三、List绑定:
需求:通常在需要批量提交数据时,将提交的数据绑定到list
中,本例子中:批量商品修改,在页面输入多个商品信息,将多个商品信息提交到controller方法中。
做法:使用List接收页面提交的批量数据,通过Controller形参中包装pojo接收,在包装pojo中定义List
属性;
(本例中在ItemsQueryVo中定义itemsList属性接收页面提交的批量商品;status.index定义了下标从0开始;.name/.price..对应了List
中ItemsCustom的属性名)
ItemsController:
View Code
ItemsQueryVo.java:
View Code
editItemsQuery.jsp:
View Code
四、Map绑定:
在包装类中定义Map对象,并添加get/set方法,action使用包装对象接收。