mybatis 父子关系查询(订单-明细)

 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>
<!--级联查询返回模型-->

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值