在使用一个表中的id,来更新另一个表所关联的数据中的某个属性置为null,在进行updateBatch更新时候会直接删掉该属性值,是无法达到置空操作的,updateById同样也是。
解决方法:可以把其字段值设为0,或者使用LambdaUpdateWrapper
public CommonResult<Boolean> updateSimpleSingleInstrumentsByCenterId(Long id) {
LambdaQueryWrapper<SingleInstrumentDO> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(SingleInstrumentDO::getInstrBelongsId, id);
List<SingleInstrumentDO> singleInstrumentDOS = singleInstrumentMapper.selectList(wrapper);
List<SingleInstrumentDO> singleInstrumentDOS1 = new ArrayList<>();
singleInstrumentDOS.forEach(singleInstrumentDO -> {
singleInstrumentDO.setInstrBelongsId(0l);
singleInstrumentDO.setInstrBelongsType(0);
singleInstrumentDOS1.add(singleInstrumentDO);
});
singleInstrumentMapper.updateBatch(singleInstrumentDOS1);
return success(true);
}
public CommonResult<Boolean> updateSimpleSingleInstrumentsByCenterId(Long id) {
LambdaUpdateWrapper<SingleInstrumentDO> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(SingleInstrumentDO::getInstrBelongsId,id);
updateWrapper.set(SingleInstrumentDO::getInstrBelongsId,null);
updateWrapper.set(SingleInstrumentDO::getInstrBelongsType,null);
singleInstrumentMapper.update(updateWrapper);
return success(true);
}