求助,在使用mybatis-plus时遇到的一个问题

public void transLikedFromRedis2DB() {
        //从 Redis 中获取点赞对象数据
        List<CommunityLike> likedDataFromRedis = redisService.getLikedDataFromRedis();
        LambdaUpdateWrapper<CommunityLike> updateWrapper = new LambdaUpdateWrapper<>();
        for (CommunityLike communityLike : likedDataFromRedis) {
            updateWrapper
                    .eq(CommunityLike::getCommunityId, communityLike.getCommunityId())
                    .eq(CommunityLike::getLikedUserId, communityLike.getLikedUserId())
                    .eq(CommunityLike::getLikedPostId, communityLike.getLikedPostId())
                    .set(CommunityLike::getStatus, communityLike.getStatus())
                    .set(CommunityLike::getUpdateTime, new Date());
            update(updateWrapper);
        }
    }

上面是代码逻辑,因为目前redis中只有两条数据,所以该for循环只会执行两次

第一次for循环执行的sql语句是这样的

但是第二次for循环执行的sql语句却是这样的

后面的截不下了,我把sql语句打一下

#sql语句
UPDATE t_community_like 
SET status=?,update_time=?,status=?,update_time=? 
WHERE community_id = ? AND liked_user_id = ? AND liked_post_id = ? AND community_id = ? AND liked_user_id = ? AND liked_post_id = ?
#参数
0(Integer), 2022-06-01 14:08:42.445(Timestamp), 0(Integer), 2022-06-01 14:08:48.754(Timestamp), 10(Long), oNtYk5I8cG_Rk6oCcUF2YBab_YGE(String), sss(String), 10(Long), oNtYk5I8cG_Rk6oCcUF2YBab_YGE(String), uuu(String)

问题就是第二次循环的时候,sql语句把上一次的条件拼接上去了,导致找不到目标数据,请求各位大佬帮帮忙,不胜感激

mybatis-plus·java
210 views
Comments
登录后评论
Sign In
·

补充一下,第一次循环的sql语句

#sql语句
UPDATE t_community_like 
SET status=?,update_time=? 
WHERE community_id = ? AND liked_user_id = ? AND liked_post_id = ?
#参数
0(Integer), 2022-06-01 14:08:42.445(Timestamp), 10(Long), oNtYk5I8cG_Rk6oCcUF2YBab_YGE(String), sss(String)

调用clear方法清空上次设置的参数