一、包装类型pojo参数绑定:

需求:商品查询controller方法中实现商品查询条件传入。

实现方法:

1)在形参中 添加HttpServletRequest request参数,通过request接收查询条件参数。

2)在形参中让包装类型的pojo接收查询条件参数。

做法:参数名和包装pojo中的属性一致即可;

(本例中:<input name="itemsCustom.name" />传递参数  和  ItemsQueryVo属性名itemsCustom一致);

二、数组绑定:

需求:商品批量删除,用户在页面选择多个商品,批量删除。

做法:将页面选择(多选)的商品id,传到controller方法的形参,方法形参使用数组接收页面请求的多个商品id。

(本例中deleteItems(Integer[] item_id)   item_id用来接收checkbox的name为item_id数组)

一、二实现如下:

ItemsController:

 1 // 商品查询
 2     @RequestMapping("/findItems")
 3     public ModelAndView findItems(ItemsQueryVo itemsQueryVo) throws Exception {
 4         
 5         List<ItemsCustom> itemsList = itemsService.findItemsList(itemsQueryVo);
 6         
 7         ModelAndView modelAndView =  new ModelAndView();
 8         modelAndView.addObject("itemsList", itemsList);
 9         modelAndView.setViewName("items/itemsList");
10         return modelAndView;
11     }
12     
13     // 批量删除 商品信息
14     @RequestMapping("/deleteItems")
15     public String deleteItems(Integer[] item_id) throws Exception{
16         // 调用service批量删除商品
17         // ...
18         
19         for(int id : item_id){
20             System.out.println("待删除的商品id:---------------->>" + id);
21         }
22         
23         return "success";
24     }
View Code

相关文章: