Take the order as an example and directly add the Code:
1. Multi-attribute Query
Java entity
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;
... getter setter...
}
Class = "orderdetail" is the preceding class. The type of the attribute logistics is a composite type 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>
The SQL query statement is as follows:
<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>
2. the attribute contains list queries.
Orderdetail has the attribute ordergoods of the list compound type. You should query the list in the attribute definition of resultmap: getordergoodslist
<result property="orderGoods.listData" select="wxShopOrder.getOrderGoodsList" column="orderSn"/>
Check the getordergoodslist query.
<! -- Obtain the order item list using the order number --> <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>
The returned result is also a resultmap -- ordergoodsmap
<resultMap id="orderGoodsMap" class="com.uid.trace.module.sale.schema.OrderGoods"><result property="goodsName" column="goodsName"/><result property="goodsNumber" column="goodsNumber"/></resultMap>