import lombok.Data;
/**
* 自定义响应结构
*/
@Data
public class ReturnResult<T> {
private int code;
private String msg;
private T data;
public static <T> ReturnResult<T> success() {
ReturnResult result = new ReturnResult<T>();
result.setCode(200);
result.setMsg("成功");
return result;
}
public static <T> ReturnResult<T> success(T data) {
ReturnResult result = new ReturnResult<T>(data);
result.setCode(200);
result.setMsg("成功");
return result;
}
public static <T> ReturnResult<T> error() {
ReturnResult result = new ReturnResult<T>();
result.setCode(2000);
result.setMsg("服务端异常");
return result;
}
public static <T> ReturnResult<T> error(String msg) {
ReturnResult result = new ReturnResult<T>(msg);
result.setCode(2000);
return result;
}
public static <T> ReturnResult<T> error(Integer code, String msg) {
return new ReturnResult<T>(code, msg);
}
public static <T> ReturnResult<T> error(Integer code, String msg, T data) {
return new ReturnResult<T>(code, msg, data);
}
private ReturnResult() {
}
private ReturnResult(String msg) {
this.msg = msg;
this.data = null;
}
private ReturnResult(T data) {
this.data = data;
}
private ReturnResult(Integer code, String msg) {
this.code = code;
this.msg = msg;
this.data = null;
}
private ReturnResult(Integer code, String msg, T data) {
this.code = code;
this.msg = msg;
this.data = data;
}
}
Result类(返回类)
于 2023-05-24 16:27:11 首次发布