Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[功能改进]: LambdaUpdateChainWrapper 添加 setNull() 方法,更加简单快捷的进行设置字段为空 #6532

Open
3 tasks done
HK-hub opened this issue Oct 14, 2024 · 2 comments

Comments

@HK-hub
Copy link

HK-hub commented Oct 14, 2024

确认

  • 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

功能改进

mybatis plus (当前版本3.5.2)在遇到字段设置为空的需求时,所提供的三个解决方案都存在缺陷。

通过调整FieldStrategy策略粒度太大,会影响全局。

通过mapper(entity, warpper) 方式通过entity和一个LambdaUpdateWrapper进行组合方式达到更新字段为null的目的

但是为什么不给LambadUpdateChainWrapper直接提供一个setNull()方法来直接设置字段为null呢。

并且我使用mapper(entity, warpper) 方式在wrapper中手动设置字段为null但是在进行sql 映射执行的时候还是会报错

参考资料

是否可以增加setNull()方法直接设置字段为null

this.lambdaUpdate()
                .setNull(PileSendOutPlan::getNextDaySend)
                .set(PileSendOutPlan::getSendType, pileSendOutPlan.getSendType())
                .set(PileSendOutPlan::getSendNow, pileSendOutPlan.getSendNow())
                .set(PileSendOutPlan::getPlanSendTime, pileSendOutPlan.getPlanSendTime())
                .eq(PileSendOutPlan::getId, pileSendOutPlan.getId())
                .update();
@lnsane
Copy link

lnsane commented Oct 28, 2024

和这种有什么区别?

this.lambdaUpdate()
                .set(PileSendOutPlan::getNextDaySend,null)
                .set(PileSendOutPlan::getSendType, pileSendOutPlan.getSendType())
                .set(PileSendOutPlan::getSendNow, pileSendOutPlan.getSendNow())
                .set(PileSendOutPlan::getPlanSendTime, pileSendOutPlan.getPlanSendTime())
                .eq(PileSendOutPlan::getId, pileSendOutPlan.getId())
                .update();

@HK-hub
Copy link
Author

HK-hub commented Oct 29, 2024

你试试能不能更新成null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants