如何在 TypeOrm 中使用 getter 和 setter。
例如离开我的用户实体
export class User {
@PrimaryGeneratedColumn()
private id: number;
@Column()
@Length(4, 20)
@IsNotEmpty()
private name: string;
@Column()
@Length(4, 100)
@IsNotEmpty()
private password: string;
public getId(): number {
return this.id;
}
public getPassword(password: string): string {
return this.password;
}
public setPassword(password: string): User {
this.password = bcrypt.hashSync(password, 8);
return this;
}
public setName(name: string): User {
this.name = name;
return this;
}
}
Run Code Online (Sandbox Code Playgroud)
我使用 orm 版本 0.2.7