mybatis对oracle数据库多字段批量更新

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cxws110/article/details/89013136

在mapper文件中如此写:

<update id="updateHK" parameterType="java.util.List" >
            update W_MM_HK_BASE hk 
            <trim prefix="set" suffixOverrides=",">
                <trim prefix="hk.f_fpsj=case" suffix="end,">
                <foreach collection="list" item="hkbase" index="index">
                when hk.hkid=#{hkbase.hkid} then #{hkbase.FFpsj}
                </foreach>
                </trim>
                <trim prefix="hk.f_fpr_id=case" suffix="end,">
                <foreach collection="list" item="hkbase" index="index">
                when hk.hkid=#{hkbase.hkid} then #{hkbase.FFprId}
                </foreach>
                </trim>
                <trim prefix="hk.f_fpr_name=case" suffix="end,">
                <foreach collection="list" item="hkbase" index="index">
                when hk.hkid=#{hkbase.hkid} then #{hkbase.FFprName}
                </foreach>
                </trim>
                <trim prefix="hk.if_havefp=case" suffix="end,">
                <foreach collection="list" item="hkbase" index="index">
                when hk.hkid=#{hkbase.hkid} then #{hkbase.ifHavefp}
                </foreach>
                </trim>
            </trim>
            <where>
            <foreach collection="list" item="hkbase" index="index" separator="or">
            hk.hkid=#{hkbase.hkid}
            </foreach>
            </where>
    </update>

效果如下:

update W_MM_HK_BASE hk set hk.f_fpsj=case when hk.hkid=? then ? when hk.hkid=? then ? end, hk.f_fpr_id=case when hk.hkid=? then ? when hk.hkid=? then ? end, hk.f_fpr_name=case when hk.hkid=? then ? when hk.hkid=? then ? end, hk.if_havefp=case when hk.hkid=? then ? when hk.hkid=? then ? end WHERE hk.hkid=? or hk.hkid=?

猜你喜欢

转载自blog.csdn.net/cxws110/article/details/89013136
今日推荐