一.定义枚举类(mybatis-plus 3.5版本适用):
1 (重要) @JsonFormat 表示返回前端是此字段(重要)或者 标注在类上@JsonFormat(shape = JsonFormat.Shape.OBJECT)前端就会显示枚举的key和value
2 implements IEnum 重写getValue()方法返回数据库存的字段
@Getter
public enum BuryingPointTypeEnum implements IEnum<String> {
MORE_THAN_ONE_QUEEN("MORE_THAN_ONE_QUEEN", "型号匹配到多个队列"),
RE_ACCESS("RE_ACCESS", "工程师重新接入"),
MODEL_STOP_SERVICE("MODEL_STOP_SERVICE", "型号停服"),
ENGINEEER_ONLINE("ENGINEEER_ONLINE", "工程师上线"),
ENGINEEER_OFFLINE("ENGINEEER_OFFLINE", "工程师离线"),
;
private String type;
@JsonFormat
private String name;
BuryingPointTypeEnum(String type, String name) {
this.type = type;
this.name = name;
}
public static BuryingPointTypeEnum getByDefault(String type, BuryingPointTypeEnum defaultValue) {
return Arrays.stream(values()).filter(e -> e.getType().equals(type)).findFirst().orElse(defaultValue);
}
public static BuryingPointTypeEnum getByType(String type) {
return getByDefault(type, null);
}
@Override
public String getValue() {
return this.type;
}
}
二 使用
在bean中类上使用枚举,就ok啦
@ApiModelProperty(value = "埋点类型")
@TableField(value = "type")
private BuryingPointTypeEnum type;