SpringMVC_参数绑定2

来源:互联网 发布:windows官网镜像 编辑:程序博客网 时间:2024/05/16 06:39

1 包装类型pojo参数绑定

 页面参数:

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

注意:itemsCustom和包装pojo的属性一致即可

controller方法形参:


2 集合类型绑定

页面定义:

controller方法定义:
@RequestMapping("deleteItems")
public String deleteItems(Items[] items_id) throws Exception{

3 list绑定

页面定义:

controller方法定义:
public class ItemsQueryVo{
private Items items;
private ItemsCustom itemsCustom;
private List<ItemsCustom> itemsList;


4 Map绑定


也通过在包装pojo中定义map类型属性。

 

在包装类中定义Map对象,并添加get/set方法,action使用包装对象接收。

包装类中定义Map对象如下:

Public class QueryVo {

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

  //get/set方法..

}

 

页面定义:
<tr><td>学生信息:</td><td>姓名:<inputtype="text"name="itemInfo['name']"/>年龄:<inputtype="text"name="itemInfo['price']"/>.. .. ..</td></tr>

Controller:
public String useraddsubmit(Model model,QueryVo queryVo)throws Exception{System.out.println(queryVo.getStudentinfo());}




0 0