mybatis 批量插入写法

mybatis批量插入写法

sql
UPDATE tb_book
SET 
update_time = CASE book_id 
    WHEN 1101 THEN 123123112 
    WHEN 1102 THEN 123123132 
END
WHERE book_id IN (1101,1102)
上下对照写 xml
    <update id="updateBatch">
        update tb_book set
        update_time =
        <foreach collection="list" item="item" index="index"
                 separator=" " open="case book_id" close="end">
            when #{item.bookId} then #{item.updateTime}
        </foreach>
        where book_id in
        <foreach collection="list" item="item" index="index"
                 separator="," open="(" close=")">
            #{item.bookId}
        </foreach>
    </update>
posted @ 2022-04-15 09:54  不一样的爪哇  阅读(106)  评论(0编辑  收藏  举报