|
|
|
@ -1,24 +1,31 @@
|
|
|
|
|
package com.ruoyi.common.core.domain;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.common.constant.HttpStatus;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 响应信息主体
|
|
|
|
|
*
|
|
|
|
|
* @author ruoyi
|
|
|
|
|
* @author Lion Li
|
|
|
|
|
*/
|
|
|
|
|
@Data
|
|
|
|
|
@NoArgsConstructor
|
|
|
|
|
public class R<T> implements Serializable {
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 成功
|
|
|
|
|
*/
|
|
|
|
|
public static final int SUCCESS = HttpStatus.SUCCESS;
|
|
|
|
|
public static final int SUCCESS = 200;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 失败
|
|
|
|
|
*/
|
|
|
|
|
public static final int FAIL = HttpStatus.ERROR;
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
public static final int FAIL = 500;
|
|
|
|
|
|
|
|
|
|
private int code;
|
|
|
|
|
|
|
|
|
|
private String msg;
|
|
|
|
@ -37,7 +44,7 @@ public class R<T> implements Serializable {
|
|
|
|
|
return restResult(null, SUCCESS, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static <T> R<T> ok(T data, String msg) {
|
|
|
|
|
public static <T> R<T> ok(String msg, T data) {
|
|
|
|
|
return restResult(data, SUCCESS, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -53,7 +60,7 @@ public class R<T> implements Serializable {
|
|
|
|
|
return restResult(data, FAIL, "操作失败");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static <T> R<T> fail(T data, String msg) {
|
|
|
|
|
public static <T> R<T> fail(String msg, T data) {
|
|
|
|
|
return restResult(data, FAIL, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -61,12 +68,33 @@ public class R<T> implements Serializable {
|
|
|
|
|
return restResult(null, code, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回警告消息
|
|
|
|
|
*
|
|
|
|
|
* @param msg 返回内容
|
|
|
|
|
* @return 警告消息
|
|
|
|
|
*/
|
|
|
|
|
public static <T> R<T> warn(String msg) {
|
|
|
|
|
return restResult(null, HttpStatus.WARN, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 返回警告消息
|
|
|
|
|
*
|
|
|
|
|
* @param msg 返回内容
|
|
|
|
|
* @param data 数据对象
|
|
|
|
|
* @return 警告消息
|
|
|
|
|
*/
|
|
|
|
|
public static <T> R<T> warn(String msg, T data) {
|
|
|
|
|
return restResult(data, HttpStatus.WARN, msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private 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;
|
|
|
|
|
R<T> r = new R<>();
|
|
|
|
|
r.setCode(code);
|
|
|
|
|
r.setData(data);
|
|
|
|
|
r.setMsg(msg);
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static <T> Boolean isError(R<T> ret) {
|
|
|
|
@ -76,28 +104,4 @@ public class R<T> implements Serializable {
|
|
|
|
|
public static <T> Boolean isSuccess(R<T> ret) {
|
|
|
|
|
return R.SUCCESS == ret.getCode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getCode() {
|
|
|
|
|
return code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setCode(int code) {
|
|
|
|
|
this.code = code;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getMsg() {
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setMsg(String msg) {
|
|
|
|
|
this.msg = msg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public T getData() {
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setData(T data) {
|
|
|
|
|
this.data = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|