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

mybatis批量写法

时间:2020-01-06 14:22:52      阅读:57      评论:0      收藏:0      [点我收藏+]

标签:art   span   ipa   sys   mod   for   into   datetime   添加   

批量更新

<update id="updPartsStatus" parameterType="com.autosys.parts.model.BesiParts">
        <foreach collection="besiParts.partIdsList" item="item" index="index" open="begin" close=";end;" separator=";">
            UPDATE TM_BESI_PART
            <set>
                STATUS = #{besiParts.status}
            </set>
            <where>
                ID = #{item}
            </where>
        </foreach>
    </update>

批量添加

<insert id="instBesiparts" parameterType="map">
        INSERT INTO TM_BESI_PART
        (
        ID,
        PART_NO,
        MODEL_CODE,
        PART_NAME,
        PART_NAME_EN,
        PART_TYPE,
        POWER_FLAG,
        PURCASING_CODE,
        REG_PLANT,
        USE_PLANT,
        PRODUCE_CODE,
        PLANT_CODE,
        NEW_FLAG,
        STATUS,
        CREATE_BY,
        CREATE_TIME,
        UPDATE_BY,
        UPDATE_TIME
        )
        <foreach collection="partsList" item="item" index="index" separator="UNION ALL">
            SELECT
            #{item.id, jdbcType=VARCHAR},
            #{item.partNo, jdbcType=VARCHAR},
            #{item.modelCode, jdbcType=VARCHAR},
            #{item.partName, jdbcType=VARCHAR},
            #{item.partNameNn, jdbcType=VARCHAR},
            #{item.partType, jdbcType=VARCHAR},
            #{item.powerFlag, jdbcType=VARCHAR},
            #{item.purcasingCode, jdbcType=VARCHAR},
            #{item.regPlant, jdbcType=VARCHAR},
            #{item.usePlant, jdbcType=VARCHAR},
            #{item.produceCode, jdbcType=VARCHAR},
            #{item.plantCode, jdbcType=VARCHAR},
            #{item.newFlag, jdbcType=VARCHAR},
            #{item.status, jdbcType=VARCHAR},
            #{item.createBy, jdbcType=VARCHAR},
            #{item.createTime, jdbcType=VARCHAR},
            #{item.updateBy, jdbcType=VARCHAR},
            #{item.updateTime, jdbcType=VARCHAR}
            FROM DUAL
        </foreach>
    </insert>

批量Merge

<insert id="instEmParts" parameterType="com.autosys.parts.model.EmParts">
        MERGE INTO TR_PART_EMER T1 USING (
        <foreach collection="emList" item="emParts" index="index" separator="UNION ALL">
            SELECT
            #{emParts.id} as ID,
            #{emParts.partCode} as PART_CODE,
            #{emParts.model} as MODEL,
            #{emParts.userId} as USER_ID,
            #{emParts.createBy} as CREATE_BY,
            sysdate as CREATE_TIME,
            #{emParts.updateBy} as UPDATE_BY,
            sysdate as UPDATE_TIME,
            #{emParts.partId} as PART_ID
            FROM
            dual
        </foreach>
        )
        T2 ON (
        T1.PART_ID = T2.PART_ID)
        WHEN MATCHED THEN
        UPDATE SET T1.USER_ID = T2.USER_ID, T1.UPDATE_TIME = T2.UPDATE_TIME, UPDATE_BY = T2.UPDATE_BY WHERE T1.PART_ID = T2.PART_ID
        WHEN NOT MATCHED THEN
        INSERT (
        ID,
        PART_CODE,
        MODEL,
        USER_ID,
        CREATE_BY,
        CREATE_TIME,
        PART_ID
        )
        VALUES
        (
        T2.ID,
        T2.PART_CODE,
        T2.MODEL,
        T2.USER_ID,
        T2.CREATE_BY,
        T2.CREATE_TIME,
        T2.PART_ID
        )
    </insert>

mybatis批量写法

标签:art   span   ipa   sys   mod   for   into   datetime   添加   

原文地址:https://www.cnblogs.com/xiaofengfree/p/12155898.html

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