![](/img/trans.png)
[英]Spring boot/Spring data jpa - how to update related entity?
[英]Spring boot with spring data jpa. How can i perform partial update of entity from request body?
基本上,我有带有更新方法的REST控制器类。
@RequestMapping(value = "{id}", method = RequestMethod.POST)
public Account update(@PathVariable Integer id, @RequestBody Account account){
.....
}
当请求正文仅包含Account对象的部分字段时,如何执行给定ID的Account对象的部分更新?
您能通过身份证获取吗? 拥有原始版本后,如果定义了属性,则可以使用新对象进行更新。 就像是:
@RequestMapping(value = "{id}", method = RequestMethod.POST)
public Account update(@PathVariable Integer id, @RequestBody Account account){
Account acc = dao.getById(id);
acc.copy(account);
dao.update(acc);
}
class Account {
....
public void copy(final Account account) {
if (account.prop1 != null) {
this.prop1 = account.prop1;
}
// update the mutable fields
.....
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.