方式一注解方式
@MppMultiId
updateByMultiId
方式二条件构造器 Wrapper
update(updateWrapper),一条一条更
方式三case when
<update id="updatePutInAndRealNum" parameterType="java.util.List" >
update batch_material
<trim prefix="set" suffixOverrides=",">
<trim prefix="real_num =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.realNum!=null">
when material_code=#{i.materialCode} and batch_id = #{i.batchId} then #{i.realNum}
</if>
</foreach>
</trim>
<trim prefix="put_in =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.putIn!=null">
when material_code=#{i.materialCode} and batch_id = #{i.batchId} then #{i.putIn}
</if>
</foreach>
</trim>
</trim>
where
<foreach collection="list" separator="or" item="i" index="index" >
material_code=#{i.materialCode} and batch_id = #{i.batchId}
</foreach>
</update>
数据量不多10条以内吧。大批量慎用,每一个case when 都要循环一遍list集合
拼接sql
update batch_material set real_num =case when material_code=? and batch_id = ? then ? when material_code=? and batch_id = ? then ? end, put_in =case when material_code=? and batch_id = ? then ? when material_code=? and batch_id = ? then ? end where material_code=? and batch_id = ? or material_code=? and batch_id = ?