package com.vincent.rsf.common.domain;
|
|
import java.io.Serializable;
|
|
/**
|
* 通用返回类
|
* Created by vincent on 2023/3/27
|
*/
|
public class BaseResult<T> implements Serializable {
|
|
private static final long serialVersionUID = -6551234415624980301L;
|
|
public static final int RESULT_OK_CODE = 0;
|
|
public static final int RESULT_ERROR_CODE = 1;
|
|
public static final String RESULT_OK_MSG = "操作成功";
|
|
public static final String RESULT_ERROR_MSG = "服务器错误";
|
|
private Integer code;
|
|
private String msg;
|
|
private T data;
|
|
public BaseResult() {
|
}
|
|
public BaseResult(Integer code) {
|
this(code, null);
|
}
|
|
public BaseResult(Integer code, String msg) {
|
this(code, msg, null);
|
}
|
|
public BaseResult(Integer code, String msg, T data) {
|
this.code = code;
|
this.msg = msg;
|
this.data = data;
|
}
|
|
public Integer getCode() {
|
return code;
|
}
|
|
public BaseResult<T> setCode(Integer code) {
|
this.code = code;
|
return this;
|
}
|
|
public String getMsg() {
|
return msg;
|
}
|
|
public BaseResult<T> setMsg(String msg) {
|
this.msg = msg;
|
return this;
|
}
|
|
public T getData() {
|
return data;
|
}
|
|
public BaseResult<T> setData(T data) {
|
this.data = data;
|
return this;
|
}
|
|
public BaseResult<T> add(T data) {
|
this.data = data;
|
return this;
|
}
|
|
public static BaseResult<?> ok() {
|
return new BaseResult<>(RESULT_OK_CODE, RESULT_OK_MSG);
|
}
|
|
public static BaseResult<?> ok(String msg) {
|
return ok().setMsg(msg);
|
}
|
|
public static BaseResult<?> error() {
|
return new BaseResult<>(RESULT_ERROR_CODE, RESULT_ERROR_MSG);
|
}
|
|
public static BaseResult<?> error(String msg) {
|
return BaseResult.error().setMsg(msg);
|
}
|
|
public static BaseResult<?> define(Integer code, String msg) {
|
return new BaseResult<>(code, msg);
|
}
|
|
public Boolean success() {
|
return this.getCode().equals(RESULT_OK_CODE);
|
}
|
|
public Boolean fail() {
|
return !success();
|
}
|
|
}
|