有时候在数据库设计的时候,我们可能会使用一些固定的值,比如启用、停用,只有这两个值,我们设计数据库可能设计成stop
、start
。这个时候,我们在Jpa中设计实体时,一般设置成枚举就更合理了。
创建枚举
public enum Status {
stop("停用"), start("启用");
private String value;
Status(String value) {
this.value = value;
}
}
实体
@Entity
@Table(name = "sys_user")
@Data
@Slf4j
public class SysUser {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long userId;
private Long deptId;
private String userName;
private String nickName;
private String userType;
private String email;
@Column(name = "phonenumber")
private String phoneNumber;
private String sex;
private String avatar;
@JsonIgnore
private String password;
@Enumerated(EnumType.STRING)
private Status status;
private String delFlag;
private String loginIp;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.sql.Timestamp loginDate;
private String createBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.sql.Timestamp createTime;
private String updateBy;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private java.sql.Timestamp updateTime;
private String remark;
private Long recycleCompanyId;
private Long medicalInstitutionId;
private Long ethnicity;
}
查询
我们可以查看一些查询的结果
评论 (0)