您的位置:首页 > 编程语言 > Java开发

struts2 复杂参数封装

2016-07-13 22:45 501 查看

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;

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: