美文网首页
restful接口封装返回实体

restful接口封装返回实体

作者: 非文666 | 来源:发表于2018-04-03 17:31 被阅读0次
package com.sq.dispatcher.core.pojo.vo;

import com.alibaba.fastjson.JSON;

public class ResponseResult<T> {

    //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接口封装返回实体

      本文链接:https://www.haomeiwen.com/subject/wcgqhftx.html