枚举实现
public enum LibraryEnum {
//故障类别
FAULT_CLASSIFICATION_1("1","松动"),
FAULT_CLASSIFICATION_2("2","程序缺失");
private String code;
private String msg;
LibraryEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
//这里就是将code翻译成对应的中文
public static String msg(String code) {
LibraryEnum[] resultStates = values();
for (LibraryEnum resultState : resultStates) {
if (resultState.code().equals(code)) {
return resultState.msg();
}
}
return null;
}
public String code(){
return this.code;
}
public String msg(){
return this.msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
LibraryEnum.msg(faultClassification);