首页 > 其他分享 >自定义返回接口类型

自定义返回接口类型

时间:2023-03-11 13:55:50浏览次数:55  
标签:返回 resultMsg String 自定义 int 接口类型 result resultCode public

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);
    }
}

标签:返回,resultMsg,String,自定义,int,接口类型,result,resultCode,public
From: https://www.cnblogs.com/maomao777/p/17205798.html

相关文章