package com.biubiu.admin.util.res;
import lombok.Getter;
import org.springframework.http.HttpStatus;
/**
* <p>
* ResultCode
* </p>
*
* @author biubiu
* @since 2021/1/23
*/
@Getter
public enum ResultCode {
/** 异常声明 */
SUCCESS(HttpStatus.OK, 200, "OK"),
BAD_REQUEST(HttpStatus.BAD_REQUEST, 400, "Bad Request"),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, 500, "Internal Server Error"),
//参数异常
PARAM_IS_INVALID(1001, "参数无效"),
PARAM_IS_BLANK(1002, "参数为空"),
PARAM_TYPE_BIND_ERROR(1003, "参数类形错误"),
//用户异常
USER_NOT_LOGGED_IN(2001, "用户未登录,需要验证,请登录"),
USER_LOGIN_ERROR(2002, "账号不存在或密码错误"),
USER_NOT_EXIST(2003, "用户不存在"),
USER_HAS_EXISTED(2004, "用户已存在")
;
/** 返回的HTTP状态码, 符合http请求 */
private final HttpStatus httpStatus;
/** 业务异常码 */
private final int code;
/** 业务异常信息描述 */
private final String message;
ResultCode(HttpStatus httpStatus, Integer code, String message) {
this.httpStatus = httpStatus;
this.code = code;
this.message = message;
}
ResultCode(Integer code, String message) {
this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
this.code = code;
this.message = message;
}
public static ResultCode getResultCode(String message) {
for (ResultCode ut : ResultCode.values()) {
if (ut.getMessage().equals(message)) {
return ut;
}
}
return null;
}
}
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
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