cjl
2023-09-26 c0c80bebcc93e90834e06404d6056322e51b02dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.moral.api.pojo.query;
 
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Description
 *
 * @Date 2020/10/27 11:00
 * @Version 1.0
 */
@Getter
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum OrderType {
 
    /**
     * ASC
     */
    ASC("ascending"),
    /**
     * DESC
     */
    DESC("descending"),
    ;
 
    private static Map<String, OrderType> valueMap = new HashMap<>();
 
    static {
        for (OrderType orderType : OrderType.values()) {
            valueMap.put(orderType.code, orderType);
        }
    }
 
    @EnumValue
    public final String code;
 
    OrderType(String code) {
        this.code = code;
    }
 
    @JsonCreator
    public static OrderType getByValue(String code) {
        OrderType result = valueMap.get(code);
        if (result == null) {
            throw new IllegalArgumentException("No element matches " + code);
        }
        return result;
    }
 
}