码迷,mamicode.com
首页 > 其他好文 > 详细

struts2 复杂参数封装

时间:2016-07-14 02:48:57      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

1.1.1    Struts2中封装复杂类型的数据:

封装到List集合:

页面:

商品名称:<input type="text" name="products[0].pname"/><br/>

商品价格:<input type="text" name="products[0].price"/><br/>

商品名称:<input type="text" name="products[1].pname"/><br/>

商品价格:<input type="text" name="products[1].price"/><br/>

商品名称:<input type="text" name="products[2].pname"/><br/>

商品价格:<input type="text" name="products[2].price"/><br/>

 

Action:

public class ProductAction1 extends ActionSupport{

private List<Product> products;

 

public List<Product> getProducts() {

    return products;

}

 

public void setProducts(List<Product> products) {

    this.products = products;

}

}

 

封装到Map集合

页面:

商品名称:<input type="text" name="map[‘one‘].pname"/><br/>

商品价格:<input type="text" name="map[‘one‘].price"/><br/>

商品名称:<input type="text" name="map[‘two‘].pname"/><br/>

商品价格:<input type="text" name="map[‘two‘].price"/><br/>

商品名称:<input type="text" name="map[‘three‘].pname"/><br/>

商品价格:<input type="text" name="map[‘three‘].price"/><br/>

 

Action:

public class ProductAction2 extends ActionSupport{

private Map<String,Product> map;

 

public Map<String, Product> getMap() {

    return map;

}

 

public void setMap(Map<String, Product> map) {

    this.map = map;

}

}

struts2 复杂参数封装

标签:

原文地址:http://www.cnblogs.com/jiemoxiaodi/p/5668491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!