读书人

Ibatis一对多的延迟加载使用

发布时间: 2012-09-19 13:43:54 作者: rapoo

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" >    <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" resultparameterresultMap="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?

?

?

读书人网 >软件架构设计

热点推荐