封裝高可複用的服務端響應物件 --ServerResponse、ResponseCode
阿新 • • 發佈:2018-12-11
在平時的編碼過程中,返回給前端的資料都會統一規範起來,用一個泛型來作為響應物件
ServerResponse類
@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(
ResponseCode 類
public enum ResponseCode { SUCCESS(0,"SUCCESS"), ERROR(1,"ERROR"), NEED_LOGIN(10,"NEED_LOGIN"), ILLEGAL_ARGUMENT(2,"ILLEGAL_ARGUMENT"); private final int code; private final String desc; ResponseCode(int code,String desc){ this.code = code; this.desc = desc; } public int getCode(){ return code; } public String getDesc(){ return desc; }}