自定义返回接口类型

ResponseResult

package com.mao.common;

public class R<T> {
    // 状态码
    Integer resultCode;
    // 具体结果
    T result;
    // 响应的信息
    String resultMsg;

    public R(int resultCode, String resultMsg, T result) {
        this.resultCode = resultCode;
        this.result = result;
        this.resultMsg = resultMsg;
    }

    public R(int resultCode, String resultMsg) {
        this.resultCode = resultCode;
        this.resultMsg = resultMsg;
    }
    public R(int resultCode) {
        this.resultCode = resultCode;
    }

    public int getResultCode() {
        return resultCode;
    }

    public void setResultCode(int resultCode) {
        this.resultCode = resultCode;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public String getResultMsg() {
        return resultMsg;
    }

    public void setResultMsg(String resultMsg) {
        this.resultMsg = resultMsg;
    }
}


ResponseResultFactory工厂类

package com.mao.common;

public class RFactory<T> {

    public static R buildR() {
        return new R(200);
    }

    public static R buildR(int code) {
        return new R(code);
    }

    public static R buildR(int resultCode, String resultMsg) {
        return new R(resultCode,resultMsg);
    }

    public static R buildR(int resultCode, String resultMsg, Object obj) {
        return new R(resultCode,resultMsg,obj);
    }
}

posted @ 2023-03-11 13:47  没有烦恼的猫猫  阅读(37)  评论(0编辑  收藏  举报