mybatis批量更新

 要根據id批量跟新name,age,modifiedDate,mapper.xml文件如下

 

<update id="batchUpdate">

    update direct_bank_sys_param

    <trim prefix="set" suffixOverrides=",">

        <trim prefix="name=case" suffix="end,">

            <foreach collection="list" item="i" index="index">

                <if test="i.name!=null">

                    when id=#{i.id} then #{i.name}

                </if>

            </foreach>

        </trim>

        <trim prefix="age=case"  suffix="end,">

            <foreach collection="list" item="i"  index="index">

                <if test="i.age!=null">

                    when id=#{i.id} then #{i.age}

                </if>

            </foreach>

        </trim>

        <trim prefix=" modifier =case"  suffix="end,">

            <foreach collection="list" item="i"  index="index">

                <if test="i.modifier!=null">

                    when id=#{i.id} then #{i.modifier}

                </if>

            </foreach>

        </trim>

    </trim>

    where

    <foreach collection="list" separator="or" item="i" index="index">

        id=#{i.id}

    </foreach>

</update>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章