青羊经侦大队-数据平台
安瑾然
2022-07-12 da52a1ba7e8fc2d8e633655484e7ff4abed319c8
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
56
57
58
59
60
61
package com.example.jz.enums;
 
public enum BusinessHttpStatus {
 
    // 未登录
    UNAUTHORIZED(401, "未登录"),
    BAD_EXCEPTION(10000, "系统异常"),
    // 成功
    SUCCESS(200, "成功");
 
    private final int value;
 
    private final String msg;
 
 
    BusinessHttpStatus(int value, String msg) {
        this.value = value;
        this.msg = msg;
    }
 
 
    /**
     * Return the integer value of this status code.
     */
    public int value() {
        return this.value;
    }
 
    /**
     * Return the msg of this status code.
     */
    public String getMsg() {
        return msg;
    }
 
    /**
     * Return a string representation of this status code.
     */
    @Override
    public String toString() {
        return this.value + " " + name();
    }
 
 
    public static BusinessHttpStatus valueOf(int statusCode) {
        BusinessHttpStatus status = resolve(statusCode);
        if (status == null) {
            throw new IllegalArgumentException("没有找到该Http状态码包含状态 [" + statusCode + "]");
        }
        return status;
    }
 
    public static BusinessHttpStatus resolve(int statusCode) {
        for (BusinessHttpStatus status : values()) {
            if (status.value == statusCode) {
                return status;
            }
        }
        return null;
    }
}