读书人

ibatis 之 复杂部类集合的属性

发布时间: 2012-08-24 10:00:21 作者: rapoo

ibatis 之 复杂类型集合的属性

Result Map还可以装入代表复杂类型对象集合(List)的属性,用以表示在数据库中相互关系为多对多或一对多的数据。拥有集合属性的类作为“一”的一方,而在集合中的对象作为“多”的一方。用来装入对象集合的mapped statement和上面例子一样。唯一的不同是,让SQL Map架构装入复杂类型集合(List)的业务对象的属性必须是java.util.List或java.util.Collection类型

?

映射文件:

?

?

?Category类:

??

?

? 注意:

????? private List productList;
?
????? public List getProductList() {
?return productList;
????? }
????? public void setProductList(List productList) {
??this.productList = productList;
???? }

?

?DAO层:

?

/** * 测试复杂类型集合的属性 * @throws SQLException */public void getProductUseComplexTypeList() throws SQLException {Category category = productDao.getProductUseComplexTypeList(1);System.out.println(category);}

?

结果:

Category---id:1
description:sports
Product----id:1
description:basketball
price:206.99

Product----id:2
description:football
price:106.99

?

?

?

?

?

?

?

?

读书人网 >软件架构设计

热点推荐