Result.java
2.14 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.glsx.model;
import java.util.HashMap;
import java.util.Map;
/**
* @Title: DemoVO.java
* @Description:
* @author deployer name
* @version V1.0
* @Company: Didihu.com.cn
* @Copyright Copyright (c) 2017
*/
public class Result extends HashMap<String,Object>{
private static final long serialVersionUID = 1L;
public static final String CODE_KEY = "code";
public static final String SUCCESS_KEY = "success";
public static final String MSG_KEY = "message";
private static final String RESULT_KEY = "result";
public static final Integer SUCCESS = 0;
public static final Integer ERROR = 9999;
public Result() {
this.put(CODE_KEY, SUCCESS);
this.put(SUCCESS_KEY, true);
this.put(MSG_KEY, "");
}
public static Result error() {
return error(ERROR, "未知错误");
}
public static Result error(String msg) {
return error(ERROR, msg);
}
public static Result error(int code, String msg) {
Result r = new Result();
r.put(CODE_KEY, code);
r.put(MSG_KEY, msg);
r.put(SUCCESS_KEY,false);
return r;
}
public static Result ok(String msg) {
Result r = new Result();
r.put(MSG_KEY, msg);
return r;
}
public static Result ok(Map<String, Object> map) {
Result r = new Result();
r.putAll(map);
return r;
}
public static Result ok() {
return new Result();
}
public Result data(Object o) {
super.put(RESULT_KEY, o);
return this;
}
public Result put(String key, Object value) {
super.put(key, value);
return this;
}
public void setMessage(String formatMessage) {
this.put(MSG_KEY, formatMessage);
}
public String getMessage() {
return (String)this.get(MSG_KEY);
}
public void setCode(int code) {
this.put(CODE_KEY, code);
}
public int getCode() {
return (Integer)this.get(CODE_KEY);
}
public Object getData() {
return this.get(RESULT_KEY);
}
public boolean isSuccess() {
return (boolean) this.get(SUCCESS_KEY);
}
}