播放 - 如何判断模型中的实例变量不应映射到数据库列?
Play - How to tell that an instance variable in model should not be mapped to a db column?
假设我有一个带有实例变量 password
的模型 class User
。但是,我只想将 passwordHash
保存到数据库中,并且实例变量将仅用作我用来临时保存原始密码的中间值,以便我可以对它进行 bcrypt。我如何告诉 Play 框架我不想将 password
变量保存到数据库中?
您需要在密码上添加“@Transient”注解:
@Entity
public class User extends Model {
@Transient
public String password;
public String passwordHash;
}
How to handle the "calculated" fields in a Play Framework model
播放框架模型
假设我有一个带有实例变量 password
的模型 class User
。但是,我只想将 passwordHash
保存到数据库中,并且实例变量将仅用作我用来临时保存原始密码的中间值,以便我可以对它进行 bcrypt。我如何告诉 Play 框架我不想将 password
变量保存到数据库中?
您需要在密码上添加“@Transient”注解:
@Entity
public class User extends Model {
@Transient
public String password;
public String passwordHash;
}
How to handle the "calculated" fields in a Play Framework model 播放框架模型