package com.wgcloud.util;
|
|
import lombok.Data;
|
|
import java.io.Serializable;
|
|
/**
|
* @author kdq
|
* @version 1.0.0
|
* @ClassName R.java
|
* @Description TODO
|
* @createTime 2023年05月11日 10:00:00
|
*/
|
@Data
|
public class R<T> implements Serializable {
|
private static final long serialVersionUID = 1L;
|
|
private int code;
|
|
private String msg;
|
|
private T data;
|
|
public static <T> R<T> ok() {
|
return restResult((T) null, CommonConstants.SUCCESS, (String)null);
|
}
|
|
public static <T> R<T> ok(T data) {
|
return restResult(data, CommonConstants.SUCCESS, (String)null);
|
}
|
|
public static <T> R<T> ok(T data, String msg) {
|
return restResult(data, CommonConstants.SUCCESS, msg);
|
}
|
|
public static <T> R<T> failed() {
|
return restResult((T)null, CommonConstants.FAIL, (String)null);
|
}
|
|
public static <T> R<T> failed(String msg) {
|
return restResult((T)null, CommonConstants.FAIL, msg);
|
}
|
|
public static <T> R<T> failed(T data) {
|
return restResult(data, CommonConstants.FAIL, (String)null);
|
}
|
|
public static <T> R<T> failed(T data, String msg) {
|
return restResult(data, CommonConstants.FAIL, msg);
|
}
|
|
static <T> R<T> restResult(T data, int code, String msg) {
|
R<T> apiResult = new R();
|
apiResult.setCode(code);
|
apiResult.setData(data);
|
apiResult.setMsg(msg);
|
return apiResult;
|
}
|
|
public R() {
|
}
|
|
public R(int code, String msg, T data) {
|
this.code = code;
|
this.msg = msg;
|
this.data = data;
|
}
|
|
}
|