mybatis批量

mapper:
void updateSpend(@Param(“params”) Object value);

xml:

<update id="updateSpend">
    UPDATE profileDailySpend
    <trim prefix="set" suffixOverrides=",">
        <trim prefix="spend =case" suffix="else spend end,">
            <foreach item="item" collection="params">
                WHEN profileId = #{item.profileId} AND clientArea = #{item.clientArea} AND date = #{item.date}
                THEN #{item.spend}
            </foreach>
        </trim>
    </trim>
    WHERE
    isManaged = 1
    此处写法:(a=b)or(a=c)or...
    <!--<foreach item="item" collection="params" open="AND (" separator="or" close=")">
        (profileDailySpend.profileId = (#{item.profileId}))
    </foreach>-->
    in写法:(in可能效率高)
    AND profileId IN
    <foreach collection="params" index="index" item="item" open="(" separator="," close=")">
        #{item.profileId}
    </foreach>
</update>

//list过长分组
private Map groupList(List list) {
int listSize=list.size();
//每组的数量
int toIndex = 1000;
Map map = new HashMap();
//记录分组id
int keyToken = 0;
for(int i = 0;i<list.size();i+=toIndex){
if(i+toIndex>listSize){
toIndex=listSize-i;
}
List newList = list.subList(i,i+toIndex);
map.put(“result”+keyToken, newList);
keyToken++;
}
return map;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值