#
cl
20 小时以前 35d8c09fd1ea3f72684c5921939fa20c92bd330b
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
package com.vincent.rsf.httpaudit.common;
 
import java.util.HashMap;
 
public class R extends HashMap<String, Object> {
 
    private static final long serialVersionUID = 1L;
 
    private static final String CODE = "code";
    private static final String MSG = "msg";
    private static final String DATA = "data";
 
    public R(Integer code, String msg) {
        super.put(CODE, code);
        super.put(MSG, msg);
    }
 
    public static R ok() {
        return parse(BaseRes.OK);
    }
 
    public static R ok(String msg) {
        R r = ok();
        r.put(MSG, msg);
        return r;
    }
 
    public static R ok(Object obj) {
        return parse(BaseRes.OK).add(obj);
    }
 
    public static R error() {
        return parse(BaseRes.ERROR);
    }
 
    public static R error(String msg) {
        R r = error();
        r.put(MSG, msg);
        return r;
    }
 
    public R add(Object obj) {
        this.put(DATA, obj);
        return this;
    }
 
    public static R parse(String message) {
        if (Cools.isEmpty(message)) {
            return parse(BaseRes.ERROR);
        }
        String[] msg = message.split("-");
        if (msg.length == 2) {
            return new R(Integer.parseInt(msg[0].replaceAll(" ", "")), msg[1]);
        } else {
            return parse("500-".concat(message));
        }
    }
}