1. public enum TestEnum {
    2. SPRING("春",1),
    3. SUMMER("夏",2),
    4. AUTUMN("秋",3),
    5. Winter("冬",4);
    6. private String msg;
    7. private Integer code;
    8. TestEnum(String msg, Integer code) {
    9. this.msg = msg;
    10. this.code = code;
    11. }
    12. public String getMsg() {
    13. return msg;
    14. }
    15. public Integer getCode() {
    16. return code;
    17. }
    18. /**
    19. * 获取msg消息
    20. *
    21. * @param testEnum 状态值
    22. * @return
    23. */
    24. public static String getMessage(TestEnum testEnum) {
    25. return testEnum.msg;
    26. }
    27. /**
    28. * 获取code码
    29. *
    30. * @param testEnum
    31. * @return
    32. */
    33. public static Integer getCode(TestEnum testEnum) {
    34. return testEnum.code;
    35. }
    36. public static String getEnumNameForValue(Integer value) {
    37. for (TestEnum testEnum : TestEnum.values()) {
    38. if (value == testEnum.code) {
    39. return testEnum.getMsg();
    40. }
    41. }
    42. return null;
    43. }
    44. }