java通用返回实体类

通用返回实体类 这里记录一下

通用的返回模版

public class ReturnResult {

    public String code;
    public String msg;
    public Object data;

    public ReturnResult() {
    }

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

    public ReturnResult(String code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    /**
     * 通用成功返回
     * @return ReturnResult
     */
    public static ReturnResult success(){
        return new ReturnResult(ReturnCode.SUCCESS.code,ReturnCode.SUCCESS.msg);
    }

    /**
     * 通用失败返回
     * @return ReturnResult
     */
    public static ReturnResult fail(){
        return new ReturnResult(ReturnCode.FAIL.code,ReturnCode.FAIL.msg);
    }

    /**
     * 通用成功返回 
     * @param data 返回的数据
     * @return ReturnResult
     */
    public static ReturnResult success(Object data){
        return new ReturnResult(ReturnCode.SUCCESS.code,ReturnCode.SUCCESS.msg,data);
    }


}

你可能感兴趣的:(java)