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;
}