Ibatis一対多の遅延ロードアプリケーション

2354 ワード

デルのアプリケーションには、1対複数の状況があります.
 
1つの卸売製品は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を取得する