MyBatis:批量更新

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/u013644146/article/details/86064106

MyBatis的批量更新:

第一种写法:

<update id="batchUpdatePushStatus">
    update test_paper
    set push_status = #{pushStatus,jdbcType=INTEGER}
    where paper_id in
    <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
        #{item.paperId,jdbcType=INTEGER}
    </foreach>
</update>

第二种写法:

<update id="batchUpdatePushStatus">
    update test_paper
    set push_status = 
    <foreach collection="list" item="item" index="index" 
        separator=" " open="case ID" close="end">
        when #{item.paperId} then #{item.push_status }
    </foreach>
    where paper_id in
    <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
        #{item.paperId,jdbcType=INTEGER}
    </foreach>
</update>

猜你喜欢

转载自blog.csdn.net/u013644146/article/details/86064106
今日推荐