Maison > base de données > tutoriel mysql > 使用resultMap实现ibatis复合数据结构查询(1.多重属性查询;2.属

使用resultMap实现ibatis复合数据结构查询(1.多重属性查询;2.属

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Libérer: 2016-06-07 15:58:29
original
1278 Les gens l'ont consulté

以订单为例,直接上代码: 1.多重属性查询 java实体 public class OrderDetail { @XmlElement(required = true) protected String orderSn; @XmlElement(required = true) protected String orderAmount; @XmlElement(required = true) protected String order

以订单为例,直接上代码:

1.多重属性查询

java实体

public class OrderDetail {

    @XmlElement(required = true)
    protected String orderSn;
    @XmlElement(required = true)
    protected String orderAmount;
    @XmlElement(required = true)
    protected String orderStatus;
    @XmlElement(required = true)
    protected String orderAddTime;
    @XmlElement(required = true)
    protected Logistics logistics;
    @XmlElement(required = true)
    protected OrderGoods orderGoods;
    @XmlElement(required = true)
    protected List<OrderDetail> listData;
Copier après la connexion
        ... getter  setter...
Copier après la connexion
}
Copier après la connexion

class="orderDetail" 即为上面的类,有个属性logistics的类型是复合类型Logistics

		<resultMap id="OrderInfoMap" class="orderDetail">
			<result property="orderSn" column="orderSn"/>
			<result property="orderAmount" column="orderAmount"/>
			<result property="orderStatus" column="orderStatus"/>
			<result property="orderStatus" column="orderAddTime"/>
			
			<result property="logistics.consignee" column="consignee"/>
			<!--  <result property="logistics.receiver" column="receiver"/> -->
			<result property="logistics.country" column="country"/>
			<result property="logistics.province" column="province"/>
			<result property="logistics.city" column="city"/>
			<result property="logistics.district" column="district"/>
			<result property="logistics.address" column="address"/>
			<result property="logistics.mobile" column="mobile"/>
			<result property="logistics.shippingName" column="shippingName"/>
			<result property="orderGoods.listData" select="wxShopOrder.getOrderGoodsList" 
			        column="orderSn"/>
		</resultMap>
Copier après la connexion
sql查询语句如下:
   <select id="getOrderDetail" parameterClass="string" resultMap="OrderInfoMap" >
      	 	select  
                  order_sn as orderSn,
                  order_amount as orderAmount,
                  order_status as orderStatus,
                  add_time as orderAddTime,
                  consignee,
                  country,
                         
                  b.region_name province,
                  c.region_name city,
                  d.region_name district,
                  address,
                  mobile,
                  shipping_name as shippingName
                  
			from  ecs_order_info  o	
				  left join ecs_region b on o.province=b.region_id
	        	  left join ecs_region c on o.city=c.region_id
	        	  left join ecs_region d on o.district=d.region_id   				
			where  order_sn=#orderSn#
        </select>
Copier après la connexion

2.属性中含有列表查询

orderDetail有个属性orderGoods的类型是List复合类型,应在resultMap的属性定义中给这个list做查询 :getOrderGoodsList

<result property="orderGoods.listData" select="wxShopOrder.getOrderGoodsList" column="orderSn"/>
Copier après la connexion

看下这个查询 getOrderGoodsList

 <!-- 通过订单号获取订单商品列表 -->
        <select id="getOrderGoodsList" parameterClass="string" resultMap="orderGoodsMap">    	 	
      	 	select goods_name as goodsName,
                   goods_number as goodsNumber
            from ecs_order_goods where order_id=
      	 	(select order_id from ecs_order_info where order_sn=#orderSn#)
        </select>
Copier après la connexion
返回结果也是一个resultMap -- orderGoodsMap
<resultMap id="orderGoodsMap" class="com.uid.trace.module.sale.schema.OrderGoods">
	<result property="goodsName" column="goodsName"/>
	<result property="goodsNumber" column="goodsNumber"/>			

</resultMap>
Copier après la connexion
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal