public enum TestEnum { SPRING("春",1), SUMMER("夏",2), AUTUMN("秋",3), Winter("冬",4); private String msg; private Integer code; TestEnum(String msg, Integer code) { this.msg = msg; this.code = code; } public String getMsg() { return msg; } public Integer getCode() { return code; } /** * 获取msg消息 * * @param testEnum 状态值 * @return */ public static String getMessage(TestEnum testEnum) { return testEnum.msg; } /** * 获取code码 * * @param testEnum * @return */ public static Integer getCode(TestEnum testEnum) { return testEnum.code; } public static String getEnumNameForValue(Integer value) { for (TestEnum testEnum : TestEnum.values()) { if (value == testEnum.code) { return testEnum.getMsg(); } } return null; }}