1.mapper xml实现
<update id="updateChannelProductTempNameAndOrder" parameterType="com.alibaba.fastjson.JSONObject"> update vm_activity_channel_product <trim prefix="set" suffixOverrides=","> <trim prefix="promotion_temp_name =case" suffix="end,"> <foreach collection="list" item="item"> <if test="item.promotionTempName!=null"> when id=#{item.id} then #{item.promotionTempName} </if> </foreach> </trim> <trim prefix="order_num =case" suffix="end,"> <foreach collection="list" item="item"> <if test="item.orderNum!=null"> when id=#{item.id} then #{item.orderNum} </if> </foreach> </trim> <trim prefix="tag_name =case" suffix="end,"> <foreach collection="list" item="item"> <if test="item.tagName!=null"> when id=#{item.id} then #{item.tagName} </if> </foreach> </trim> </trim> <where> <foreach collection="list" separator="or" item="item"> id = #{item.id} </foreach> </where> </update>
2.mapper接口定义
void updateChannelProductTempNameAndOrder( List<JSONObject> list);
3.接口实现
//定义一个批量更新集合 List<JSONObject> list = new ArrayList<>(); for (Object obj : channelProductArray) { list.add((JSONObject) obj); } if(list.size()>0){ //执行批量更新 vmActivityChannelProductDao.updateChannelProductTempNameAndOrder(list); }