package com.qiwu.miao.chat.bo; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.qiwu.miao.chat.common.ResponseCode; import java.io.Serializable; /** * @author 苗权威 * @dateTime 19-6-22 上午10:42 */ @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) public class ServerResponse implements Serializable { private int status; private String msg; private T data; private ServerResponse(int status) { this.status = status; } private ServerResponse(int status, T data) { this.status = status; this.data = data; } private ServerResponse(int status, String msg) { this.status = status; this.msg = msg; } private ServerResponse(int status, String msg, T data) { this.status = status; this.msg = msg; this.data = data; } @JsonIgnore public boolean isSuccess() { return this.status == ResponseCode.SUCCESS.getCode(); } public int getStatus() { return status; } public String getMsg() { return msg; } public T getData() { return data; } public static ServerResponse createBySuccess() { return new ServerResponse<>(ResponseCode.SUCCESS.getCode()); } public static ServerResponse createBySuccessMsg(String msg) { return new ServerResponse<>(ResponseCode.SUCCESS.getCode(), msg); } public static ServerResponse createBySuccessData(T data) { return new ServerResponse<>(ResponseCode.SUCCESS.getCode(), data); } public static ServerResponse createBySuccessMsgData(String msg, T data) { return new ServerResponse<>(ResponseCode.SUCCESS.getCode(), msg, data); } public static ServerResponse createByError() { return new ServerResponse<>(ResponseCode.ERROR.getCode()); } public static ServerResponse createByErrorMsg(String msg) { return new ServerResponse<>(ResponseCode.ERROR.getCode(), msg); } public static ServerResponse createByErrorCodeMsg(int errorCode, String errorMsg) { return new ServerResponse<>(ResponseCode.ERROR.getCode(), errorMsg); } }