通用Vo封装写法

EntityResp类

import com.github.wxiaoqi.security.common.constant.RespCode;

/**
 * 响应报文实体
 * 
 * @author lvxk
 * @date 2019-10-24下午5:12:52
 *
 */
public class EntityResp {


    private int status;// 状态码

    private String message;// 信息
    
    private T data;// 数据

    public EntityResp() {
        
    }
    
    public EntityResp(RespCode respCode) {
        this.status = respCode.getCode();
        this.message = respCode.getMsg();
    }

    public EntityResp(RespCode respCode, String message) {
        this.status = respCode.getCode();
        this.message = respCode.getMsg() + ":" + message;
    }

    public EntityResp(RespCode respCode, String message, T data) {
        this.status = respCode.getCode();
        this.message = respCode.getMsg() + ":" + message;
        this.data = data;
    }

    public EntityResp(RespCode respCode, T data) {
        this(respCode);
        this.data = data;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}

枚举类写法RespCode

/**
 * 
 * @author lvxk
 * @date   2019年10月23日
 */
public enum RespCode {
    PARAMETER_ERROR(40200,"参数异常"),
    BILL_STATUS_ERROR(40201,"单据状态异常"),
    UPLOAD_ERROR(40202,"上传文件异常"),
    SERVER_ERROR(40203,"服务器异常"),
    NO_SYNC_DATA(40204,"没有同步数据"),
    FILEUPLOAD_ERROR(40205,"文件上传异常"),
    FILE_ERROR(40206,"文件异常"),
    SUCCESS(200,"请求成功"),
    // 用户token异常
    EX_TOKEN_ERROR_CODE(40101,"EX_TOKEN_ERROR_CODE"),
    EX_USER_INVALID_CODE(40102,"用户token无效"),
    // 客户端token异常
    EX_CLIENT_INVALID_CODE(40131,"EX_CLIENT_INVALID_CODE"),
    EX_CLIENT_FORBIDDEN_CODE(40331,"EX_CLIENT_FORBIDDEN_CODE"),
    EX_OTHER_CODE(500,"EX_OTHER_CODE")
    ;
    private int status;//状态码
    private String message;//信息
    
    private RespCode(int status,String message) {
//      CommonConstants CommonConstants 
        this.status = status;
        this.message = message;
    }
    
    public int getCode() {
        return  this.status;
    }
    
    public String getMsg() {
        return this.message;
    }
}

你可能感兴趣的:(通用Vo封装写法)