枚举类型的声明有两种方式
两种声明方式的查询条件语句不同
public enum AuditState {
未审核(1), 审核未通过(2), 审核通过(3), 审核中(4);
private int value;
AuditState(int value) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
public enum DelState {
正常, 已删除;
}
hibernate实体类与数据库对应时一般使用注解
@Enumerated(EnumType.ORDINAL)
两种不同声明方式的枚举型查询时有些许不同
//DelState
delState='正常'
//AuditState
auditState = 1//2,3,4
扩展枚举,一般用于接口返回状态定义
public enum MsgEnum {
Service_Error("101", "系统服务异常"),
Res_Success("200", "处理成功"),
Res_Undeal("201", "无需处理"),
Result_Null("202","没有数据"),
Req_Param_Null("301", "请求参数缺失"),
Req_Param_Error("302", "请求参数错误"),
private String code;
private String label;
private MsgEnum(String code, String label) {
this.code = code;
this.label = label;
}
public String getLabel() {
return label;
}
public String getCode() {
return code;
}
}