枚举类的定义
1、可以用于定义常量
2、根据类型code获取对应的中文意思
public enum VacationTypes { //请假类型 1、年休 2、病假 3、事假 4、工伤假 5、婚假 6、产假 7、护理假 8、丧假 FuneralLeave("8","丧假"), NursingLeave("7","护理假"), MaternityLeave("6","产假"), MarriageLeave("5","婚假"), InjuryLeave("4","工伤假"), CompassionateLeave("3","事假"), SickLeave("2","病假"), AnnualLeave("1","年休"); private String code; private String message; public static String getValue(String key) { VacationTypes[] values = values(); for (VacationTypes type : values) { if (type.getCode().equals(key)) { return type.getMessage(); } } return ""; } VacationTypes( String code,String message) { this.code = code; this.message = message; } public String getCode() { return code; } public String getMessage() { return message; } }
根据code获取中文
VacationTypes.getValue(type);
获取对应的code
VacationTypes.FuneralLeave.getCode()