<updateid="updateOrderItem"parameterType="java.util.List"> update order_item <trimprefix="set"suffixOverrides=","> <trimprefix="orderId = case"suffix="end,"> <foreachcollection="list"item="item"> <iftest="item.orderId != null"> when id=#{item.id} then #{item.orderId} </if> </foreach> </trim> <trimprefix="productId = case"suffix="end,"> <foreachcollection="list"item="item"> <iftest="item.productId != null"> when id=#{item.id} then #{item.productId} </if> </foreach> </trim> <trimprefix="count = case"suffix="end,"> <foreachcollection="list"item="item"> <iftest="item.count != null"> when id=#{item.id} then #{item.count} </if> </foreach> </trim> </trim> where id in <foreachcollection="idNames"index="index"item="item"open="("separator=","close=")"> <iftest="item.objectId != null"> #{item.id} </if> </foreach> </update>
对应SQL
1 2 3
[cn.srblog.dao.OrderItemMapper.updateOrderItem]-==> Preparing: update order_item set count =casewhen id=? then ? when id=? then ? endwhere id in (?,?) [cn.srblog.dao.OrderItemMapper.updateOrderItem]-==> Parameters: 1(Integer), 66(Integer), 2(Integer), 5(Integer),1(Integer), 2(Integer) [cn.srblog.dao.OrderItemMapper.updateOrderItem]-<== Updates: 3