Mybatis 批量操作

来源:互联网 发布:联发科cpu全开软件 编辑:程序博客网 时间:2024/06/05 06:45

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)
0 0