码迷,mamicode.com
首页 > 其他好文 > 详细

MyBatis一对多和多对多xml配置

时间:2019-07-08 23:56:47      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:pre   pid   ESS   from   public   sql   odi   column   desc   

MyBatis一对多和多对多xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ktcx.models.business.busfreighttemplate.dao.BusFreightTemplateDao">


    <sql id="BaseColumn">
        id,
        partner_id,
        create_by,
        create_date,
        code,
        is_del,
        end_update_date,
        name,
        type,
        area,
        is_default
    </sql>


    <resultMap id="myResultMap"
               type="com.ktcx.models.business.busfreighttemplate.model.BusFreightTemplate">
        <id property="id" column="id"></id>

        <result property="partnerId" column="partnerId"/>
        <result property="code" column="code"/>
        <result property="partnerId" column="partnerId"/>
        <result property="endUpdateDate" column="endUpdateDate"/>
        <result property="name" column="name"/>
        <result property="type" column="type"/>
        <result property="area" column="area"/>
        <result property="isDefault" column="isDefault"/>

        <collection property="freightProvices"
                    ofType="com.ktcx.models.bq.freightprovice.model.FreightProvice">
            <id column="fpId" property="id"/>

            <result property="proviceText" column="fpProviceText"/>
            <result property="code" column="fpCode"/>
            <result property="increaseFee" column="fpIncreaseFee"/>
            <result property="increaseNum" column="fpIncreaseNum"/>
            <result property="startFee" column="fpStartFee"/>
            <result property="startNum" column="fpStartNum"/>
            <result property="proviceName" column="fpProviceName"/>
            <result property="proviceId" column="fpProviceId"/>
            <result property="shopId" column="fpShopId"/>
            <result property="templateId" column="fpTemplateId"/>
        </collection>


    </resultMap>


    <!--一对多的查询-->
    <select id="selectTemplateAndFreight" resultMap="myResultMap">
    SELECT
        ft.id,
        ft.partner_id AS partnerId,
        ft.code ,
        ft.end_update_date AS  endUpdateDate,
        ft.name ,
        ft.type ,
        ft.area ,
        ft.is_default AS  isDefault,
        fp.id fpId,
        fp.shop_id AS fpShopId  ,
        fp.provice_id AS fpProviceId ,
        fp.provice_name AS fpProviceName ,
        fp.start_num  AS fpStartNum ,
        fp.start_fee  AS fpStartFee ,
        fp.increase_num AS fpIncreaseNum ,
        fp.increase_fee AS fpIncreaseFee ,
        fp.code AS fpCode ,
        fp.provice_text AS  fpProviceText ,
        fp.template_id AS fpTemplateId
    FROM
     (
       SELECT
        f.id,
        f.partner_id ,
        f.code ,
        f.end_update_date  ,
        f.name ,
        f.type ,
        f.area ,
        f.is_default ,
        f.is_del,
        f.create_date
        FROM
        bus_freight_template f
        LEFT JOIN bus_freight_provice p
        ON f.id = p.template_id
        WHERE f.code = p.code
        AND f.code = #{code}
        GROUP BY f.id
        LIMIT #{startPage},#{pageSize}

     ) ft

      LEFT JOIN bus_freight_provice fp
        ON ft.id = fp.template_id
    WHERE ft.code = fp.code
      AND fp.template_id IS NOT NULL
      AND ft.code =  #{code}
      AND fp.is_del = '0'
      AND ft.is_del = '0'

      order by ft.create_date desc
    </select>


    <select id="getALLTemplate" resultType="int">
        SELECT COUNT(0) FROM bus_freight_template WHERE is_del = '0' AND CODE= #{code}
    </select>


    <insert id="saveData">
        insert into bus_freight_template(
        <include refid="BaseColumn"/>
        )
        VALUES
        (
        #{id},
        #{partnerId},
        #{createBy},
        #{createDate},
        #{code},
        #{isDel},
        #{endUpdateDate},
        #{name},
        #{type},
        #{area},
        #{isDefault}
        )

    </insert>

</mapper>

MyBatis一对多和多对多xml配置

标签:pre   pid   ESS   from   public   sql   odi   column   desc   

原文地址:https://www.cnblogs.com/upuptop/p/11154637.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!