java - 如何更新实体中的单个数据?
问题描述
如何仅更新我的实体中的一个数据?
@Entity
@Table(name="user")
public class UserEntity {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
private String name;
private String surname;
private String email;
private String password;
private String token; //THIS
}
我只想更新表中的令牌,如何使用存储库或其他方式来做到这一点?
解决方案
默认情况下,如果
id
-property 是,存储库实现将考虑一个新实体null
您必须通过 id 获取现有数据userEntity
并在此检索到的对象上设置令牌。然后使用保存此对象repo.save(userEntity)
推荐阅读
- c - 我可以在 C 中设置无限输入吗(K&R 练习 1-16)
- php - 如何修复标题可能不包含多个标题,检测到新行
- javascript - 无论如何要在页面加载时覆盖 og:image 内容 url,以便覆盖的图像在预览时可见。我需要显示差异预览图像
- jenkins - 自定义 Jenkins bash 环境
- asp.net-web-api - 如何使用 .NET 4.6.1 在 Insights 中记录每个 Web api 请求
- flutter - 用 nfc_manager 获取卡数据?
- bash - Https api 访问问题
- asp.net - 这种重定向称为什么以及如何为基于 ASP 的站点设置它?
- javascript - 内部的 https.request 等待获取不起作用
- .htaccess - Laravel 8 .htaccess 中的重写规则不执行任何操作