mybatis实现批量修改,性能最好
根据我个人的测试,mybatis实现批量修改的方式有很多,但从既方便又快捷的角度考虑,发现使用下面的写法性能最好,插入大批量的数据速度极快,虽然写起来复杂,数量多,但是性能好,推荐使用下面这种写法,具体示例如下:
<!-- 批量修改信息 -->
<update id="updateBatch" parameterType="Test">
update table_test a
<trim prefix="set" suffixOverrides=",">
<trim prefix="a.test_value=case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.testValue != null">
when a.test_id = #{i.testId} then #{i.testValue}
</if>
</foreach>
</trim>
<trim prefix="a.remarks=case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.remarks != null">
when a.test_id = #{i.testId} then #{i.remarks}
</if>
</foreach>
</trim>
</trim>
where a.test_id in
<foreach collection="list" item="t" open="(" close=")" separator=",">
#{t.testId}
</foreach>
</update>
经常分享一些好用的代码示例,希望与大家共同学习,共同交流!