高可用复用类

package com.kevin;

import java.io.Serializable;

import sun.font.CreatedFontTracker;

public class ServerResponse<T> implements Serializable {
private int status;
private String msg;
private T data;
public ServerResponse(int status) {
this.status = status;
}
public ServerResponse(int status,T data) {
this.status = status;
this.data = data;
}
public ServerResponse(int status,String msg,T data) {
this.data = data;
this.status = status;
this.msg = msg;
}
public ServerResponse(int status,String msg) {
this.status = status;
this.msg = msg;
}

public boolean isSuccess(){
return this.status == ResponseCode.SUCCESS.getcode();

}
public int getStatus(){
return status;
}
public T getData(){
return data;
}
public String getMsg(){
return msg;
}
public static <T> ServerResponse<T> createBySuccess(){
return new ServerResponse<T>(ResponseCode.SUCCESS.getcode());
}
public static <T> ServerResponse<T> createBySuccessMessage(String msg){
return new ServerResponse<T>(ResponseCode.SUCCESS.getcode(),msg);
}
public static <T> ServerResponse<T> createBySuccess(T data){
return new ServerResponse<T>(ResponseCode.SUCCESS.getcode(),data);
}
public static <T> ServerResponse<T> createBySuccess(String msg,T data){
return new ServerResponse<T>(ResponseCode.SUCCESS.getcode(),msg,data);
}
public static <T> ServerResponse<T> createByError(){
return new ServerResponse<T>(ResponseCode.ERROR.getcode(),ResponseCode.ERROR.getdesc());
}
public static <T> ServerResponse<T> createByErrorMessage(String errorMessage){
return new ServerResponse<T>(ResponseCode.ERROR.getcode(),errorMessage);
}
public static <T> ServerResponse<T> createByErrorCodeMessage(int errorCode,String errorMessage){
return new ServerResponse<T>(errorCode,errorMessage);
}
}

posted on 2018-05-05 10:16  JETIME庚  阅读(98)  评论(0编辑  收藏  举报

导航