mybatis plus更新表操作插入null值

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

@Test
public void updateBatchTest(){

    long startTime = System.currentTimeMillis();

    List ids = Arrays.asList(1,2,3,6,7,8,9,10);
    List 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("更新字段后查询数据:{}", userList);

    log.info("批量更新状态:{}", updateBatch);

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

}

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

@Test
public void updateBatchTest(){

    long startTime = System.currentTimeMillis();

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

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

    boolean updateBatch = userService.saveOrUpdateBatch(userList);
    log.info("更新字段后查询数据:{}", userList);
    log.info("批量更新状态:{}", updateBatch);

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

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

}

将设置字段为空放在更新年龄之后,则成功将更新字段为空和更新的年龄字段值都成功进库

具体原因欢迎大佬留言

你可能感兴趣的:(mybatisplus,mysql,mysql,mybatisplus,java,数据库,sql)