标签:code,java,MedDoctorStatusEnum,JSONObject,枚举,enumsObj,return,模板,desc From: https://www.cnblogs.com/guangxiang/p/17602426.html
import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
@Getter
public enum MedDoctorStatusEnum {
ONLINE(0,"上线"),
A_SHORT_BREAK(1,"小憩"),
OFFLINE(2,"离线");
private Integer code;
private String desc;
MedDoctorStatusEnum(Integer code, String desc) {
this.desc = desc;
this.code = code;
}
/**
* 根据code获取value
* @param code
* @return
*/
public static String getValueByCode(Integer code){
for(MedDoctorStatusEnum enumsObj: MedDoctorStatusEnum.values()){
if(code.equals(enumsObj.getCode())){
return enumsObj.getDesc();
}
}
return null;
}
public static JSONObject loopEnums(){
JSONObject jsonObject = new JSONObject();
for(MedDoctorStatusEnum enumsObj: MedDoctorStatusEnum.values()){
jsonObject.put(enumsObj.getCode().toString(),enumsObj.getDesc());
}
return jsonObject;
}
}