package com.lunhan.xxx.entity.enums; import java.util.Arrays; import java.util.Objects; /** * 通用排序类型 枚举 */ public enum EOrderBy { /** * 自增id=1, */ ID("自增id", 1), /** * 创建时间=2, */ CREATE_TIME("创建时间", 2), /** * 更新时间=3, */ UPDATE_TIME("更新时间", 3); private String desc;//枚举描述 private Integer value;//枚举值 public Integer getValue() { return value; } public String getDesc() { return desc; } /** * 构造方法 * @param desc 枚举描述 * @param value 枚举值 */ EOrderBy(String desc, Integer value) { this.desc = desc; this.value = value; } /** * 根据值获取枚举 * * @param value 枚举值 * @return */ public static EOrderBy getByValue(Integer value) { return Arrays.stream(EOrderBy.values()) .filter(e -> Objects.equals(e.getValue(), value)) .findAny() .orElse(null); } @Override public String toString() { return "EOrderBy{" + "desc='" + desc + '\'' + ", value=" + value + '}'; } }