欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Mybatis批量修改聯(lián)合主鍵數(shù)據(jù)的兩種方法

 更新時(shí)間:2022年04月11日 15:06:26   作者:豬思馬記  
最近遇上需要批量修改有聯(lián)合主鍵的表數(shù)據(jù),找很多資料都不是太合適,最終自己摸索總結(jié)了兩種方式可以批量修改數(shù)據(jù),對Mybatis批量修改數(shù)據(jù)相關(guān)知識感興趣的朋友一起看看吧

最近遇上需要批量修改有聯(lián)合主鍵的表數(shù)據(jù),網(wǎng)上找了很多文章,最終都沒找到比較合適的方法,有些只能支持少量數(shù)據(jù)批量修改,超過十幾條就不行了。

最終自己摸索總結(jié)了兩種方式可以批量修改數(shù)據(jù)。

第一種:

 <update id="updateMoreEmpOrg" parameterType="java.util.List">
        update hr_emp_org
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="ISMAN = CASE EMPID" suffix="end,">
                <foreach collection="empOrgList" item="item" index="index">
                    <if test="item.isman != null">
                        when EMPID = #{item.empid} then #{item.isman}
                    </if>
                </foreach>
            </trim>
            <trim prefix="UPDATETIME = CASE EMPID" suffix="end,">
                <foreach collection="empOrgList" item="item" index="index">
                    <if test="item.updatetime != null">
                        when EMPID = #{item.empid} then #{item.updatetime}
                    </if>
                </foreach>
            </trim>

            <trim prefix="hr_status =case EMPID" suffix="end,">
                <foreach collection="empOrgList" item="item" index="index">
                    <if test="item.hrStatus != null">
                        when #{item.EMPID} then #{item.hrStatus}
                    </if>
                </foreach>
            </trim>
        </trim>
        where
        EMPID in
        <foreach collection="empOrgList" item="item" open="(" separator="," close=")">
            #{item.empid}
        </foreach>
        and ORGID in
        <foreach collection="empOrgList" item="item" open="(" separator="," close=")">
            #{item.orgid}
        </foreach>
    </update>

直接結(jié)果集來兩個(gè)in查詢,最終可以滿足。

第二種:

 <update id="updateMoreEmpPosition" parameterType="java.util.List">
        update hr_emp_position
        <trim prefix="set" suffixOverrides=",">
            <trim prefix="ISMAN =case" suffix="end,">
                <foreach collection="empPositionList" item="item" index="index">
                    <if test="item.isman != null">
                        when EMPID = #{item.empid} and POSITIONID = #{item.positionid} then #{item.isman}
                    </if>
                </foreach>
            </trim>
            <trim prefix="CREATETIME =case" suffix="end,">
                <foreach collection="empPositionList" item="item" index="index">
                    <if test="item.createtime != null">
                        when EMPID = #{item.empid} and POSITIONID = #{item.positionid} then #{item.createtime}
                    </if>
                </foreach>
            </trim>
            <trim prefix="UPDATETIME =case" suffix="end,">
                <foreach collection="empPositionList" item="item" index="index">
                    <if test="item.updatetime != null">
                        when EMPID = #{item.empid} and POSITIONID = #{item.positionid} then #{item.updatetime}
                    </if>
                </foreach>
            </trim>
            <trim prefix="hr_status =case" suffix="end,">
                <foreach collection="empPositionList" item="item" index="index">
                    <if test="item.hrStatus != null">
                        when EMPID = #{item.empid} and POSITIONID = #{item.positionid} then #{item.hrStatus}
                    </if>
                </foreach>
            </trim>
        </trim>
        where
        EMPID in
        <foreach collection="empPositionList" item="item" open="(" separator="," close=")">
            #{item.empid}
        </foreach>
    </update>

修改條件中trim里面 case后面不填對比字段,在if里面進(jìn)行對比判斷。

到此這篇關(guān)于Mybatis批量修改聯(lián)合主鍵數(shù)據(jù)的兩種方法的文章就介紹到這了,更多相關(guān)Mybatis批量修改數(shù)據(jù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Springboot中如何使用過濾器校驗(yàn)PSOT類型請求參數(shù)內(nèi)容

    Springboot中如何使用過濾器校驗(yàn)PSOT類型請求參數(shù)內(nèi)容

    在Springboot中創(chuàng)建過濾器,用來過濾所有POST類型請求并獲取body中的參數(shù)進(jìn)行校驗(yàn)內(nèi)容是否合法,該方法僅適用于POST類型請求,本文給大家介紹Springboot中如何使用過濾器校驗(yàn)PSOT類型請求參數(shù)內(nèi)容,感興趣的朋友一起看看吧
    2023-08-08
  • java實(shí)現(xiàn)簡單的爬蟲之今日頭條

    java實(shí)現(xiàn)簡單的爬蟲之今日頭條

    最近在學(xué)習(xí)搜索方面的東西,需要了解網(wǎng)絡(luò)爬蟲方面的知識,雖然有很多開源的強(qiáng)大的爬蟲,但本著學(xué)習(xí)的態(tài)度,想到之前在做資訊站的時(shí)候需要用到爬蟲來獲取一些文章,今天剛好有空就研究了一下.在網(wǎng)上看到了一個(gè)demo,使用的是Jsoup,我拿過來修改了一下,有需要的朋友可以參考
    2016-11-11
  • Spring-cloud Feign 的深入理解

    Spring-cloud Feign 的深入理解

    這篇文章主要介紹了Spring-cloud Feign 的深入理解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2019-02-02
  • Java實(shí)現(xiàn)多用戶注冊登錄的幸運(yùn)抽獎(jiǎng)

    Java實(shí)現(xiàn)多用戶注冊登錄的幸運(yùn)抽獎(jiǎng)

    這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)多用戶注冊登錄的幸運(yùn)抽獎(jiǎng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-11-11
  • 最新評論