//示例:根据ids更新scores
UPDATE score_card a JOIN
(
SELECT 1 AS id, '1.00' AS score
UNION
SELECT 2 AS id, '2.00' AS score
) b USING(id)
SET a.score=b.score;
…join on实现,性能高效快捷-详情后补
<update id="updateScoreCard" parameterType="scoreCard">
UPDATE score_card a
JOIN (
<foreach collection="list" item="item" index="index" open="" close="" separator="UNION">
SELECT #{item.id} AS id,
#{item.score} AS score
</foreach>
)b using(id)
SET a.score = b.score
</update>
public int bitchUpdateScoreCard(Map<String,String> map) {
List<Map<String,String>> list = new ArrayList<>();
int j =0;
//遍历接参
if(map !=null && !map.isEmpty()){
String[] ids = map.get("id").split(",");
String[] scores = map.get("score").split(",");
for(int i = 0;i <=ids.length-1;i++){
Map<String,String> bitchMap = new HashMap<>();
bitchMap.put("id",ids[i]);
bitchMap.put("score",scores[i]);
list.add(bitchMap);
}
}
if(list.size()>0){
j = scoreCardMapper.bitchUpdateScoreCard(list);
}
return j;
}