forked from whgojp/JavaSecLab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathR.java
More file actions
72 lines (58 loc) · 1.37 KB
/
R.java
File metadata and controls
72 lines (58 loc) · 1.37 KB
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
62
63
64
65
66
67
68
69
70
71
72
package top.whgojp.common.utils;
import java.util.HashMap;
import java.util.Map;
/**
* @description 规范返回结果
* @author: whgojp
* @email: whgojp@foxmail.com
* @Date: 2024/5/ueditor 12:45
*/
public class R extends HashMap<String, Object> {
public R() {
put("code", 0);
put("msg", "success");
}
public static R error() {
return error(500, "服务未知异常");
}
public static R error(String msg) {
return error(500, msg);
}
public static R error(int code, String msg) {
R r = new R();
r.put("code", code);
r.put("msg", msg);
return r;
}
public static R ok(String msg) {
R r = new R();
r.put("msg", msg);
return r;
}
public static R ok(String msg, String data) {
R r = new R();
r.put("msg", msg);
r.put("data", data);
return r;
}
public static R ok(Map<String, Object> map) {
R r = new R();
r.putAll(map);
return r;
}
public static R ok() {
return new R();
}
public R setPage(Object value) {
super.put("page", value);
return this;
}
public R setData(Object value) {
super.put("data", value);
return this;
}
public R put(String key, Object value) {
super.put(key, value);
return this;
}
}