mybatis plus更新表操作插入null值

本文通过代码示例展示了在使用MyBatis Plus进行批量更新时,若设置字段为空,其更新行为会受字段顺序影响。当用户名、密码字段设置为空后,再更新年龄字段,只有年龄字段的更新会成功;而如果先更新为空的字段,再更新年龄,则所有设定都能正确写入数据库。
摘要由CSDN通过智能技术生成

看如下代码, 模拟我之前遇到的场景

@Test
public void updateBatchTest(){

    long startTime = System.currentTimeMillis();

    List<Integer> ids = Arrays.asList(1,2,3,6,7,8,9,10);
    List<BatchUser> userList = userMapper.selectBatchIds(ids);
    log.info("查询原始数据:{}", userList);

     log.info("更新 user_name,pass_word 字段为空");
    int updateCount = userMapper.updateList(ids);
    log.info("更新数据条数:{}", updateCount);

    for (BatchUser user : userList) {
        // 更新年龄
        user.setAge(9);
    }

    boolean updateBatch = userService.saveOrUpdateBatch(userList);
    log.info("批量更新状态:{}", updateBatch);

    long endTime = System.currentTimeMillis();
    log.info("耗时 -> {}ms ", (endTime - startTime));

}

如果将用户名、密码字段设置为空, 再更新年龄字段值,最后只有年龄值被更新,用户名、密码为空却不能更新进库,程序正常执行完成

@Test
public voi

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值