前端通用返回接口类

package com.runbrick.msg;

/**
 * {@code ResultMsg} <前端通用返回>
 *
 * @author chow
 * @version 1.0
 * @since 1.8
 */
public class ResultMsg {

    private Integer error = 200;
    private String msg = "请求成功";
    private Object data;


    private ResultMsg(Integer error, String msg, Object data) {
        this.error = error;
        this.msg = msg;
        this.data = data;
    }

    public Integer getError() {
        return error;
    }

    public void setError(Integer error) {
        this.error = error;
    }

    public String getMsg() {
        return msg;
    }

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

    public Object getData() {
        return data;
    }

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

    @Override
    public String toString() {
        return "ResultMsg{" +
                "error=" + error +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }


    public static ResultMessageBuilder builder() {
        return new ResultMessageBuilder();
    }


    public static class ResultMessageBuilder {

        private Integer error = 200;
        private String msg = "请求成功";
        private Object data;

        public Integer getError() {
            return error;
        }

        public ResultMessageBuilder setError(Integer error) {
            this.error = error;
            return this;
        }

        public String getMsg() {
            return msg;
        }

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

        public Object getData() {
            return data;
        }

        public ResultMessageBuilder setData(Object data) {
            this.data = data;
            return this;
        }

        public ResultMessageBuilder() {
        }

        public ResultMsg build() {
            if (data == null) {
                throw new RuntimeException("返回结果必填!");
            }
            return new ResultMsg(error, msg, data);
        }
    }

}
# Java 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×