数据返回包装类

import java.io.Serializable;

public class Rs implements Serializable {
private static final int CODE_SUCCESS = 200;
private static final int CODE_FAIL = 90000;
private static final int CODE_ERROR = 90000;
private static final int CODE_NO_PERMISSION = 90001;
private static final long serialVersionUID = 5393448305311433341L;
protected int code;
protected String msg;
protected T data;

public Rs(int code, String msg, T data) {
    this.code = code;
    this.msg = msg;
    this.data = data;
}

public static <T> Rs<T> success() {
    return new Rs(200, "success", (Object)null);
}

public static <T> Rs<T> success(String message) {
    return new Rs(200, message, (Object)null);
}

public static <T> Rs<T> success(T data) {
    return new Rs(200, "success", data);
}

public static <T, P extends Tip> Rs<T> success(Op<T, P> data) {
    if (data.getExp() != null) {
        return error(data.exp().getMessage());
    } else if (data.getTip() != null) {
        return data.getTip() instanceof DefaultTip && ((DefaultTip)data.getTip()).isNoPermission() ? noPermission(data.getTip().getContent(), data.some()) : error(data.getTip().getContent());
    } else {
        return data.getSome() != null ? success(data.some()) : success();
    }
}

public static <T> Rs<T> success(Opt<T> data) {
    if (data.getExp() != null) {
        return error(data.exp().getMessage());
    } else if (data.getTip() != null) {
        return data.getTip() != null && data.getTip().isNoPermission() ? noPermission(data.getTip().getContent(), data.some()) : error(data.getTip().getContent());
    } else {
        return data.getSome() != null ? success(data.some()) : success();
    }
}

public static <T> Rs<T> success(String message, T data) {
    return new Rs(200, message, data);
}

public static <T> Rs<T> error() {
    return new Rs(90000, "fail", (Object)null);
}

public static <T> Rs<T> error(String message) {
    return new Rs(90000, message, (Object)null);
}

public static <T> Rs<T> error(T data) {
    return new Rs(90000, "fail", data);
}

public static <T> Rs<T> error(String message, T data) {
    return new Rs(90000, message, data);
}

public static <T> Rs<T> badrequest() {
    return new Rs(90000, "no identifier arguments", (Object)null);
}

public static <T> Rs<T> badrequest(String message) {
    return new Rs(90000, message, (Object)null);
}

public static <T> Rs<T> badrequest(T data) {
    return new Rs(90000, "no identifier arguments", data);
}

public static <T> Rs<T> badrequest(String message, T data) {
    return new Rs(90000, message, data);
}

public static <T> Rs<T> noPermission(String message, T data) {
    return new Rs(90001, message, data);
}

public void setMsg(String msg) {
    this.msg = msg;
}

public int getCode() {
    return this.code;
}

public String getMsg() {
    return this.msg;
}

public T getData() {
    return this.data;
}

}

上一篇:案例--正则 + replace() // 替换敏感词


下一篇:数据库_分组函数_分组查询