package com.zzh.common; import org.codehaus.jackson.annotate.JsonIgnore; import org.codehaus.jackson.map.annotate.JsonSerialize; import java.io.Serializable; /** * Created by lenovo on 2018/6/20. */ @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) //保证序列化json的时候,如果是null的对象,key也会消失 public class ServerResponse <T> 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, T data) { this.status = status; this.msg = msg; this.data = data; } private ServerResponse(int status,String msg){ this.status = status; this.msg = msg; } @JsonIgnore //使之不在json序列化结果当中 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); } /*进一步封装*/ public static <T> ServerResponse<T> createByResult(boolean result){ if (result){ return createBySuccess(); }else{ return createByError(); } } }

zuidaama LV2
4月20日
zhangbo2020 LV6
4月17日
微信网友_6444139264921600 LV8
2月25日
zolscy LV24
2024年11月28日
krispeng LV15
2024年10月31日
233002037 LV3
2024年10月20日
xiquyiyuan LV10
2024年8月28日
TY0165 LV20
2024年6月22日
alsk222 LV4
2024年5月10日
ruozizz LV3
2024年4月21日

微信网友_6956978011000832 LV2
7月27日
zuidaama LV2
4月20日
zhangbo2020 LV6
4月17日
jinxinquq
3月30日
暂无贡献等级
Javatopone
3月29日
暂无贡献等级
哪里的完整版 LV8
3月6日
qibodong LV15
2月28日
2636804923 LV6
2月24日
xiejingxun LV2
2024年12月31日
zruth30 LV1
2024年12月8日