美文网首页
返回类型封装

返回类型封装

作者: 穿长裙的年代 | 来源:发表于2021-03-18 11:47 被阅读0次

    1、普通类型

    public class Result {
        public final int code;
        public final String msg;
    
        public Result(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }
        public Result() {
            code = 0;
            msg = "请求成功";
        }
        public static final Result SUCCESS = new Result();
        public static final Result FAILURE = new Result(-1, "操作异常");
        public static final Result PARAM_ERROR = new Result(-1, "参数错误");
    }
    
    

    2、带数据返回类型

    public class ResultDetail<T> extends Result{
    
        public final T data;
    
        public ResultDetail(int code, String msg, T data) {
            super(code, msg);
            this.data = data;
        }
        public ResultDetail(T data) {
            super(0, "请求成功");
            this.data = data;
        }
    }
    

    相关文章

      网友评论

          本文标题:返回类型封装

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