欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

封装接口统一返回数据结构

程序员文章站 2022-06-01 12:49:59
...
package cn.toroot.bj.utils;

/**
 * Created on 2020-6-10 16:52:10
 * Mr peng
 */

import cn.toroot.bj.core.constant.ResponseCodeConstant;

import java.io.Serializable;


public class HttpResponseBody<E> implements Serializable {

    /**
     * Comment for <code>serialVersionUID</code>
     */
    private static final long serialVersionUID = -5406928126690333502L;

    private String code;

    private String msg;

    private E data;

    public HttpResponseBody(){
    }

    public HttpResponseBody(String code, String msg, E data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

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

    public String getCode() {
        return code;
    }

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

    public String getMsg() {
        return msg;
    }

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

    public E getData() {
        return data;
    }

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


    public static HttpResponseBody successResponse(String message) {
        return new HttpResponseBody(ResponseCodeConstant.SUCCESS, message);
    }

    public static <T> HttpResponseBody<T> successResponse(String message,T singleData) {
        return new HttpResponseBody<T>(ResponseCodeConstant.SUCCESS, message,singleData);
    }

    public static HttpResponseBody failResponse(String message) {
        return new HttpResponseBody(ResponseCodeConstant.FAIL, message);
    }

}



相关标签: java