ResultModel.java 1.8 KB
Newer Older
manxiaoqiang committed
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
package util;

/**
 * Created by nolan on 15/11/2016.
 * description:
 */
public class ResultModel {

    /**
     * 返回码
     */
    private int code;

    /**
     * 返回结果描述
     */
    private String message;

    /**
     * 返回内容
     */
    private Object content;

    public ResultModel(int code, String message) {
        this.code = code;
        this.message = message;
        this.content = "";
    }

    public ResultModel(int code, String message, Object content) {
        this.code = code;
        this.message = message;
        this.content = content;
    }

    public ResultModel(ResultStatus status) {
        this.code = status.getCode();
        this.message = status.getMessage();
        this.content = "";
    }

kangxiaoshan committed
42 43 44 45 46 47
    public ResultModel(String erro) {
        this.code = ResultStatus.FAILED.getCode();
        this.message = erro;
        this.content = "";
    }

manxiaoqiang committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
    public ResultModel(ResultStatus status, Object content) {
        this.code = status.getCode();
        this.message = status.getMessage();
        this.content = content;
    }

    public static ResultModel OK(Object content) {
        return new ResultModel(ResultStatus.SUCCESS, content);
    }

    public static ResultModel OK() {
        return new ResultModel(ResultStatus.SUCCESS);
    }

    public static ResultModel ERROR(ResultStatus error) {
        return new ResultModel(error);
    }

kangxiaoshan committed
66 67 68 69
    public static ResultModel ERROR(String errorMessage) {
        return new ResultModel(errorMessage);
    }

70 71 72 73
    public static ResultModel ERROR(int code,String errorMessage) {
        return new ResultModel(code,errorMessage);
    }

manxiaoqiang committed
74 75 76 77 78 79 80 81 82 83 84 85
    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Object getContent() {
        return content;
    }
}