字典表中的数据定义为枚举

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.Objects;

/**
* 路线技术等级枚举
*/
public enum JSDJEnum {

GS("10", "高速"),
YJ("11", "一级"),
EJ("22", "二级"),
SJ("23", "三级"),
SI("24", "四级"),
WJ("30", "等外");

@EnumValue
private final String code;
@EnumValue
private final String desc;

@JsonValue
public String getCode() {
return this.code;
}

@JsonValue
public String getDesc() {
return this.desc;
}

JSDJEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}

@JsonCreator
public static JSDJEnum getByCode(String code) {
for (JSDJEnum value : JSDJEnum.values()) {
if (Objects.equals(code, value.getCode())) {
return value;
}
}
return null;
}
}
posted @ 2022-05-25 18:49  懂得归零  阅读(145)  评论(0编辑  收藏  举报