java Mybatis-plus更新某个字段为null

2022-07-23 11:25:33

在不加注解@TableField(updateStrategy = FieldStrategy.IGNORED)的情况下(因为@TableField(updateStrategy = FieldStrategy.IGNORED)注解会踩坑),

用Wrappers.lambdaUpdate()更新:

LambdaUpdateWrapper<Entrust> lambdaUpdateWrapper = Wrappers.lambdaUpdate();
        lambdaUpdateWrapper.eq(Entrust::getWtId, wtId);
        lambdaUpdateWrapper.set(Entrust::getStatus, EntrustConstant.YWT_STATUS_1);
        lambdaUpdateWrapper.set(Entrust::getWtStatus, null);
        entrustService.update(null, lambdaUpdateWrapper);

如果想批量更新:

// 更新下面的预委托样品编号都为空
        List<Sample> sampleList = sampleService.lambdaQuery().eq(Sample::getWtId, wtId).list();
        List<Integer> sampleIds = new ArrayList<>(6);
        // 一个委托单下最多四个样品
        for (Sample sample : sampleList) {
            sampleIds.add(sample.getSampleId());
        }
        LambdaUpdateWrapper<Sample> updateWrapper = new UpdateWrapper<Sample>().lambda()
                .set(Sample::getPreSampleNo, null)
                .in(Sample::getSampleId, sampleIds);
        sampleService.update(null, updateWrapper);
  • 作者:lllll520520520520520
  • 原文链接:https://blog.csdn.net/lllll520520520520520/article/details/124753550
    更新时间:2022-07-23 11:25:33