您的位置:首页 > 其它

Mybatis 批量操作

2018-04-10 16:38 260 查看

1. TestMapper

// 批量修改
int updateBatch(@Param("id") int[] id, String test);


2. TestMapper.xml

<update id="updateBatch">
UPDATE table_name
SET test = #{1}
WHERE id IN
<foreach collection="id" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</update>


3. 调用

int[] id = new int[]{1, 2, 3};
updateBatch(id, "test");
// 相当于执行如下 sql 语句 :
// UPDATE table_name SET test = 'test' WHERE id IN (1,2,3)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mybatis