xuxiuxi
2017-03-20 6db786eadb2c242e0b08e56d47edd08f58e12102
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
package cn.com.basic.face.discern.common;
 
import java.util.List;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.xutils.http.annotation.HttpResponse;
 
@HttpResponse(parser = JsonResponseParser.class)
public class ResultBean {
    public static final String OK = "0";
    private String code;
    private String message;
    private Object data;
    public String getCode() {
        return code;
    }
    public void  setCode(String code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void  setMessage(String message) {
        this.message = message;
    }
    public Object getData() {
        return data;
    }
    public void  setData(Object data) {
        this.data = data;
    }
 
    public <T> T getBeanOfType(Class<T> requiredType) {
        if (data != null) {
            if (data instanceof JSONObject) {
                JSONObject jsonObj = (JSONObject) data;
                return JSON.parseObject(jsonObj.toJSONString(), requiredType);
            }
        }
        return null;
    }
 
    public <T> List<T> getListBeanOfType(Class<T> requiredType) {
        if (data != null) {
            if (data instanceof JSONArray) {
                JSONArray jsonArray = (JSONArray) data;
                return JSON.parseArray(jsonArray.toJSONString(), requiredType);
            }
        }
        return null;
    }
 
    public boolean isSuccess() {
        if (OK.equals(getCode())) {
            return true;
        } else {
            return false;
        }
    }
 
}