package com.lunhan.xxx.entity.enums; import java.util.Arrays; import java.util.Objects; public enum ESex { /** * 男=1, */ MALE("男", 1), /** * 女=2, */ FEMALE("女", 2), /** * 其他=3, */ OTHER("其他", 3); /** * 枚举描述 */ private String desc; /** * 枚举值 */ private Integer value; public Integer getValue() { return value; } public String getDesc() { return desc; } /** * 构造方法 * @param desc 枚举描述 * @param value 枚举值 */ ESex(String desc, Integer value) { this.desc = desc; this.value = value; } /** * 根据值获取枚举 * * @param value 枚举值 * @return */ public static ESex getByValue(Integer value) { return Arrays.stream(ESex.values()) .filter(e -> Objects.equals(e.getValue(), value)) .findAny() .orElse(null); } @Override public String toString() { return "ESex{" + "desc='" + desc + '\'' + ", value=" + value + '}'; } }