-
业务场景:
-
批量插入sku配置信息;
-
-
注意事项:
-
foreach标签的使用;
-
最终生成的是一条sql:UPDATE (fileds ... ) VALUES (values1 ... ), (values2 ... ), (values3 ...);
-
-
实际代码:
-
mapper层:
Integer batchInsertTeamActivitySkuConfig(@Param("teamActivitySkuConfigPOList") List<TeamActivitySkuConfigPO> teamActivitySkuConfigPOList);
-
xml:
<insert id="batchInsertTeamActivitySkuConfig" parameterType="java.util.List"> INSERT INTO `team_activity_sku_config` <trim prefix="(" suffix=")" suffixOverrides=","> `sku_config_id`, `config_id`, `operation_activity_id`, `merchant_id`, `spu_id`, `sku_id`, `activity_start_time`, `activity_end_time`, `activity_stock`, `status`, `sku_min_price`, `sku_max_price`, `total_limit_per_sku`, `leader_target_user_type`, `leader_target_reward`, `follower_target_user_type`, `follower_target_reward`, `team_members_num`, </trim> VALUES <foreach collection="teamActivitySkuConfigPOList" item="item" separator=","> <trim prefix="(" suffix=")" suffixOverrides=","> #{item.skuConfigId}, #{item.configId}, #{item.operationActivityId}, #{item.merchantId}, #{item.spuId}, #{item.skuId}, #{item.activityStartTime}, #{item.activityEndTime}, #{item.activityStock}, #{item.status}, #{item.skuMinPrice}, #{item.skuMaxPrice}, #{item.totalLimitPerSku}, #{item.leaderTargetUserType}, #{item.leaderTargetReward}, #{item.followerTargetUserType}, #{item.followerTargetReward}, #{item.teamMembersNum}, </trim> </foreach> </insert>
-
MyBatis-批量插入
最新推荐文章于 2024-08-31 10:26:32 发布