ibatis延迟加载的功能

对于1:N或者1:1的对象,如何一次取出,可以参考已有的代码,ibatis有延迟加载的功能。至于jsp里怎么取子对象的值,非常简单,和class中的写法一样,如business.businessServcieList,这样再对此做遍历处理。


一个产品对应3条Rage信息

public class ProductVo implements Serializable {
private List<WholesaleRange> wholeRageList; //Rage信息集合

public List<WholesaleRange> getWholeRageList() {
return wholeRageList;
}

public void setWholeRageList(List<WholesaleRange> wholeRageList) {
this.wholeRageList = wholeRageList;
}
}

<typeAlias alias="wholesaleprd" type="com.woyo.business.wholesale.domain.model.ProductVo" />

<resultMap id="wholesalePriceRageMap" class="wholesaleprd" >
<result column="id" property="id" jdbcType="VARCHAR" />
<result column="title" property="title" jdbcType="VARCHAR" />
<result column="is_mixed_batch" property="mixedBatch" nullValue="0" />
<result column="id" property="wholeRageList" select="getWholeRageList"/>
</resultMap>


//这个可以是其他sql.xml下的sql语句
<select id="getWholeRageList" resultClass="wholesaleRage" parameterClass="long">
select id as id , whilesale_id as whilesaleId , quantity as quantity , price as price from wholesale_range where whilesale_id = #value# order by quantity
</select>

我在项目中的规范:
DOMAIN对象中,增加了很多和表字段无关的属性,目的就是为了返回一个扁平的grid。这样的做法是不对的。原则上,domain对象中,只有和数据库表对应的属性和setter/getter,另外可以加上一些getStatusDesc等为了在页面上显示的东西。对于主从关系的类,不要把主从关系的类的属性,直接搬到当前类中,要用对象的形式体现。对于1:N的关系,只要在1中增加对N的引用,不要在N中增加对1的引用。如Business 和 BusiessService的关系,在Business中增加一个List<BusiessService>属性即可,不要在BusiessService再增加Business属性,也不要在Business中增加BusinessServcie.BusinessServcieName引用,更不要在BusinessSQL.xml中,去取BusinessServcie.BusinessServcieName并返回。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值