MyBatisPlus 不能更新null
MybatisPlus的update默认机制是更新字段时判断是否为null,做值为null,则不更新该字段
当我们需要将部分字段更新为null时,可利用UpdateWrapper解决该问题
UpdateWrapper用法
WarehouseItem warehouseItem = warehouseItemService.getById(2117733125);
UpdateWrapper<WarehouseItem> updateWrapper = new UpdateWrapper<>();
//可将指定字段更新为null
updateWrapper.set("ownerId", null);
updateWrapper.set("product_id",123456);
warehouseItemService.update(warehouseItem, updateWrapper);
//修改值
User user = new User();
user.setStatus(true);
user.setName("zhangsan");
//修改条件
UpdateWrapper<User> userUpdateWrapper = new UpdateWrapper<>();
userUpdateWrapper.eq("name", "lqf");
//这个必须填写修改主键,代表修改哪条记录
updateWrapper.eq("id",user.getId());
int update = baseMapper.update(user, userUpdateWrapper);
https://blog.csdn.net/fly_or/article/details/121093337
https://blog.csdn.net/ncnhhm/article/details/129406785
/**
* 附件相关
*/
@Schema(description="附件相关")
@TableField(updateStrategy = FieldStrategy.IGNORED)
private String relevantFiles;
//1.主表
ProProject po = new ProProject();
//this.saveOrUpdate(po );
//2.转map 赋值null
Map<String, Object> mp = new HashMap<>();
mp = BeanUtil.beanToMap(po);
mp.put("taskId",null);
//3.在转回po ,保存
ProProject po = new ProProject();
po = BeanUtil.toBeanIgnoreCase(mp, ProProjectTaskCompanyLaunchEntity.class, false);
po.setApplyType(1);
po.setStatusValue(0);
po.setStatusName("草稿");
this.save(po);
择善人而交,择善书而读,择善言而听,择善行而从。