Mybatis 批量操作

    xiaoxiao2021-03-25  100

    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)
    转载请注明原文地址: https://ju.6miu.com/read-19817.html

    最新回复(0)