-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathR.java
More file actions
71 lines (57 loc) · 1.58 KB
/
R.java
File metadata and controls
71 lines (57 loc) · 1.58 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
package com.yjz.notepad.bean;
import java.util.HashMap;
/**
* author: YJZ
* date: 2018/10/18
* des: 返回数据的基类
*/
public class R extends HashMap<String, Object> {
private static final String status = "status";
private static final String message = "message";
private static final String data = "data";
private R() {
put(status, 200);
put(message, "操作成功");
}
public R(int code, String msg) {
put(status, code);
put(message, msg);
}
public static R error() {
return error(1, "操作失败");
}
public static R error(int code, String msg) {
return new R(code, msg);
}
public static R error(String msg) {
return error(0, msg);
}
public static R ok(String msg, Object object) {
R r = new R();
r.put(message, msg);
r.put(data, object);
return r;
}
public static R ok(String msg, boolean isSuccess, String message) {
R r = new R();
r.put(message, msg);
HashMap<String, Object> hashMap = new HashMap<>();
hashMap.put("isSuccess", isSuccess);
hashMap.put("message", message);
r.put(data, hashMap);
return r;
}
public static R ok(boolean isSuccess, String message) {
return ok("请求成功", isSuccess, message);
}
public static R ok(String msg) {
R r = new R();
r.put(message, msg);
return r;
}
public static R ok(HashMap<String, Object> map) {
R r = new R();
r.putAll(map);
return r;
}
}