Skip to content

[疑问] 字段如何设置不能通过 updateById 来更新仅能通过 createUpdate() 来更新 #317

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

Closed
tanyaofei opened this issue Apr 24, 2025 · 4 comments
Assignees
Labels

Comments

@tanyaofei
Copy link
Contributor

tanyaofei commented Apr 24, 2025

环境

java: 1.8.0_131
hsweb: 3.0.5

问题说明

因为有一个字段是 progress,前端走的更新 updateById,希望能避免前端传值更新到此字段。
后台有任务单独对这个 progress 单独维护。

尝试过设置 @Column(updatable = false),但这样 createUpdate() 也无法进行更新

@zhou-hao
Copy link
Member

方式一: 重写接口方法,实体类设置为null
方式二:监听 EntityPrepareModifyEvent 通过上下文判断是否可以更新某个字段。如果不能,就将after的字段设置为before的字段。

@tanyaofei
Copy link
Contributor Author

感谢回复,是否考虑增加类似mbp的updateStrategy=NOT_NULL来控制呢

@zhou-hao
Copy link
Member

感谢回复,是否考虑增加类似mbp的updateStrategy=NOT_NULL来控制呢

update本身会忽略null值。 目前两种方式其实都是走createUpdate。后续看能否通过上下文传递强制更新。

@tanyaofei
Copy link
Contributor Author

感谢回复~

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

No branches or pull requests

2 participants