1.单参数关联查询
<!--订单基础信息-->
<resultMap id="BaseResultMap" type="com.pmys.saas.match.sdk.domain.order.OrderInfo">
<id column="pkid" jdbcType="BIGINT" property="pkid"/>
<result column="quotation_id" jdbcType="BIGINT" property="quotationId"/>
<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
<result column="mer_open_id" jdbcType="VARCHAR" property="merOpenId"/>
<result column="mer_app_id" jdbcType="VARCHAR" property="merAppId"/>
<result column="account_id" jdbcType="BIGINT" property="accountId"/>
<result column="account_name" jdbcType="VARCHAR" property="accountName"/>
<result column="order_status" jdbcType="TINYINT" property="orderStatus"/>
<result column="op_type" jdbcType="TINYINT" property="opType"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="cust_open_id" jdbcType="VARCHAR" property="custOpenId"/>
<result column="cust_nick_name" jdbcType="VARCHAR" property="custNickName"/>
<result column="cust_qq" jdbcType="VARCHAR" property="custQq"/>
<result column="attn_head" jdbcType="VARCHAR" property="attnHead"/>
<result column="attn_name" jdbcType="VARCHAR" property="attnName"/>
<result column="attn_phone" jdbcType="VARCHAR" property="attnPhone"/>
<result column="attn_address" jdbcType="VARCHAR" property="attnAddress"/>
<result column="is_tax" jdbcType="TINYINT" property="isTax"/>
<result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
<result column="order_price" jdbcType="DECIMAL" property="orderPrice"/>
<result column="freight" jdbcType="DECIMAL" property="freight"/>
<result column="add_time" jdbcType="TIMESTAMP" property="addTime"/>
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
</resultMap>
<!--订单商品信息-->
<resultMap id="OrderProductResultMap" type="com.pmys.saas.match.sdk.domain.order.OrderProduct">
<id column="pkid" jdbcType="BIGINT" property="pkid"/>
<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
<result column="product_code" jdbcType="VARCHAR" property="productCode"/>
<result column="brand_name" jdbcType="VARCHAR" property="brandName"/>
<result column="quantity" jdbcType="BIGINT" property="quantity"/>
<result column="sale_price" jdbcType="DECIMAL" property="salePrice"/>
<result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
<result column="is_tax" jdbcType="TINYINT" property="isTax"/>
<result column="add_time" jdbcType="TIMESTAMP" property="addTime"/>
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
</resultMap>
<!--级联查询返回模型-->
<resultMap id="DeatilResultMap" extends="BaseResultMap" type="com.pmys.saas.match.sdk.domain.order.response.OrderDtoResponse">
<id column="order_no" jdbcType="BIGINT" property="orderNo"/>
<collection property="orderProducts" ofType="com.pmys.saas.match.sdk.domain.order.OrderProduct" column="order_no" select="queryOrderProductList"/>
</resultMap>
<!--级联查询父订单主信息-->
<select id="queryOrderDtoList" parameterType="com.pmys.saas.match.sdk.domain.order.request.OrderRequest"
resultMap="DeatilResultMap">
select
<include refid="Base_Column_List"/>
from qd_order qo
<include refid="Base_Where"/>
order by qo.add_time
<if test="page.pageSize !=null and page.start !=null">
limit ${page.start},${page.pageSize}
</if>
</select>
<!--级联查询订单项信息-->
<select id="queryOrderProductList" resultMap="OrderProductResultMap" parameterType="java.lang.String">
select * from qd_order_product where order_no = #{orderNo}
</select>
<!--级联查询返回模型-->
2.多参数需要传到子节点
<!--订单基础信息-->
<resultMap id="BaseResultMap" type="com.pmys.saas.match.sdk.domain.order.OrderInfo">
<id column="pkid" jdbcType="BIGINT" property="pkid"/>
<result column="quotation_id" jdbcType="BIGINT" property="quotationId"/>
<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
<result column="mer_open_id" jdbcType="VARCHAR" property="merOpenId"/>
<result column="mer_app_id" jdbcType="VARCHAR" property="merAppId"/>
<result column="account_id" jdbcType="BIGINT" property="accountId"/>
<result column="account_name" jdbcType="VARCHAR" property="accountName"/>
<result column="order_status" jdbcType="TINYINT" property="orderStatus"/>
<result column="op_type" jdbcType="TINYINT" property="opType"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="cust_open_id" jdbcType="VARCHAR" property="custOpenId"/>
<result column="cust_nick_name" jdbcType="VARCHAR" property="custNickName"/>
<result column="cust_qq" jdbcType="VARCHAR" property="custQq"/>
<result column="attn_head" jdbcType="VARCHAR" property="attnHead"/>
<result column="attn_name" jdbcType="VARCHAR" property="attnName"/>
<result column="attn_phone" jdbcType="VARCHAR" property="attnPhone"/>
<result column="attn_address" jdbcType="VARCHAR" property="attnAddress"/>
<result column="is_tax" jdbcType="TINYINT" property="isTax"/>
<result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
<result column="order_price" jdbcType="DECIMAL" property="orderPrice"/>
<result column="freight" jdbcType="DECIMAL" property="freight"/>
<result column="add_time" jdbcType="TIMESTAMP" property="addTime"/>
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
</resultMap>
<!--订单商品信息-->
<resultMap id="OrderProductResultMap" type="com.pmys.saas.match.sdk.domain.order.OrderProduct">
<id column="pkid" jdbcType="BIGINT" property="pkid"/>
<result column="order_no" jdbcType="VARCHAR" property="orderNo"/>
<result column="product_code" jdbcType="VARCHAR" property="productCode"/>
<result column="brand_name" jdbcType="VARCHAR" property="brandName"/>
<result column="quantity" jdbcType="BIGINT" property="quantity"/>
<result column="sale_price" jdbcType="DECIMAL" property="salePrice"/>
<result column="total_price" jdbcType="DECIMAL" property="totalPrice"/>
<result column="is_tax" jdbcType="TINYINT" property="isTax"/>
<result column="add_time" jdbcType="TIMESTAMP" property="addTime"/>
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
</resultMap>
<!--级联查询返回模型-->
<resultMap id="DeatilResultMap" extends="BaseResultMap" type="com.pmys.saas.match.sdk.domain.order.response.OrderDtoResponse">
<id column="order_no" jdbcType="BIGINT" property="orderNo"/>
<id column="is_tax" jdbcType="TINYINT" property="isTax"/>
<collection property="orderProducts" ofType="com.pmys.saas.match.sdk.domain.order.OrderProduct" column="orderNo=order_no,isTax=is_tax" select="queryOrderProductList"/>
</resultMap>
<!-- orderNo/isTax是定义的变量名, order_no/is_tax是主表的字段order_no/is_tax
先查出主表的结果, 然后主表记录数是几 就执行几次 collection 的select,
javaType和ofType 写不写都行,
select的值: 对应xml的namespace + 对应xml中的代码片段的id,
column作为select语句的参数传入,如果只传一个参数id可以简写: column="id" -->
<!--级联查询父订单主信息-->
<select id="queryOrderDtoList" parameterType="com.pmys.saas.match.sdk.domain.order.request.OrderRequest"
resultMap="DeatilResultMap">
select
<include refid="Base_Column_List"/>
from qd_order qo
<include refid="Base_Where"/>
order by qo.add_time
<if test="page.pageSize !=null and page.start !=null">
limit ${page.start},${page.pageSize}
</if>
</select>
<!--级联查询订单项信息-->
<select id="queryOrderProductList" resultMap="OrderProductResultMap" parameterType="java.util.Map">
select * from qd_order_product where order_no = #{orderNo} and is_tax=#{isTax}
</select>
<!--级联查询返回模型-->