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;
|
}
|
}
|