restful接口封装返回实体

package com.sq.dispatcher.core.pojo.vo;

import com.alibaba.fastjson.JSON;

public class ResponseResult {

    //0表示正常
    public static final int SUCCESS_CODE = 0;

    public static final int ERROR_CODE = 1;

    /**
     * 成功
     */
    public static final ResponseResult SUCCESS = new ResponseResult(SUCCESS_CODE, "SUCCESS");
    /**
     * 失败
     */
    public static final ResponseResult ERROR = new ResponseResult(ERROR_CODE, "ERROR");

    //返回状态码
    private int code;

    //提示信息
    private String msg;

    //数据类型
    private T data;

    public ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResponseResult() {

    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
 public String toString() {
        return JSON.toJSONString(this);
    }
}

你可能感兴趣的:(restful接口封装返回实体)