青羊经侦大队-数据平台
baizonghao
2023-05-19 1c3f11dfd7493a4c4a8d41e2499477840bcc070c
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
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;
    }
 
    public int value() {
        return this.value;
    }
 
    public String getMsg() {
        return msg;
    }
 
    @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;
    }
}