Java动态sql⼀条语句实现批量修改1. DAO层
Integer updateUserList(
@Param(value ="list") List<Integer> userIdList);
<update id="updateUserList">
UPDATE user_info
<trim prefix="set" suffixOverrides=",">
<trim prefix="age=case" suffix="end,">
<foreach collection="list" item="cus">
WHEN user_id =#{cus.userId} THEN #{cus.age}
</foreach>
</trim>
<trim prefix="address=case" suffix="end,">
<foreach collection="list" item="cus">
WHEN user_id =#{cus.userId} THEN #{cus.address}
</foreach>
</trim>
</trim>
<where>
<foreach collection="list" separator="or" item="cus">
批量更新sql语句user_id =#{cus.userId}
</foreach>
</where>
</update>
3.执⾏输出
UPDATE user_info
SET age =
CASE
WHEN user_id =30069 THEN 18
WHEN user_id =30068 THEN 20
END,
address =
CASE
WHEN user_id =30069 THEN '浙江杭州'
WHEN user_id =30068 THEN '四川成都'
END
WHERE user_id =30069 OR user_id =30068
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论