在不加注解@TableField(updateStrategy = FieldStrategy.IGNORED)的情况下(因为@TableField(updateStrategy = FieldStrategy.IGNORED)注解会踩坑),
用Wrappers.lambdaUpdate()更新:
LambdaUpdateWrapperlambdaUpdateWrapper = 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 sampleList = sampleService.lambdaQuery().eq(Sample::getWtId, wtId).list();
List sampleIds = new ArrayList<>(6);
// 一个委托单下最多四个样品
for (Sample sample : sampleList) {
sampleIds.add(sample.getSampleId());
}
LambdaUpdateWrapper updateWrapper = new UpdateWrapper().lambda()
.set(Sample::getPreSampleNo, null)
.in(Sample::getSampleId, sampleIds);
sampleService.update(null, updateWrapper);



