Ibatis一对多的延迟加载应用

我们的应用之中有一个一对多的情况 :

 

一个批发产品对应3条批发价格信息

 

于是model 结构 ; 

 

public class ProductVo implements Serializable {


    private List<WholesaleRange> wholeRageList;       //价格信息集合

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

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


}

 

如何查询批发信息的时候直接带出附加的价格信息集合呢 ?

 

SQLMAP 如下构建:

 

<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>



<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>



 <select id="getWholeSaleById" resultMap="wholesalePriceRageMap" parameterClass="long">
    SELECT w.id as id ,w.title as title, p.id as prdId,p.product_name AS prdName ,p.count - w.order_amount AS balance_amount ,
    p.price AS price, p.image_url AS imageUrl, w.supplier_name, w.supplier_tel, w.wholesale_amount,
    w.wholesale_price, w.team_price, w.team_save, w.order_amount, w.team_amount ,w.is_mixed_batch
    FROM wholesale w left join  product  p on w.product_id = p.id
    
    where w.id = #value#
 </select>

 

 

这样, 查询出的对象, Ibatis 会用延迟加载的策略来得到 wholeRageList 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值