|
@@ -22,7 +22,7 @@ import java.io.Serializable;
|
|
|
* @author xuyuxiang
|
|
|
* @date 2022/8/15 16:08
|
|
|
**/
|
|
|
-public class CommonResult<T> implements Serializable{
|
|
|
+public class CommonResult<T> implements Serializable {
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
public static final int CODE_SUCCESS = 200;
|
|
|
public static final int CODE_ERROR = 500;
|
|
@@ -47,6 +47,7 @@ public class CommonResult<T> implements Serializable{
|
|
|
|
|
|
/**
|
|
|
* 获取code
|
|
|
+ *
|
|
|
* @return code
|
|
|
*/
|
|
|
public Integer getCode() {
|
|
@@ -55,13 +56,16 @@ public class CommonResult<T> implements Serializable{
|
|
|
|
|
|
/**
|
|
|
* 获取msg
|
|
|
+ *
|
|
|
* @return msg
|
|
|
*/
|
|
|
public String getMsg() {
|
|
|
return this.msg;
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 获取data
|
|
|
+ *
|
|
|
* @return data
|
|
|
*/
|
|
|
public T getData() {
|
|
@@ -70,6 +74,7 @@ public class CommonResult<T> implements Serializable{
|
|
|
|
|
|
/**
|
|
|
* 给code赋值,连缀风格
|
|
|
+ *
|
|
|
* @param code code
|
|
|
* @return 对象自身
|
|
|
*/
|
|
@@ -80,6 +85,7 @@ public class CommonResult<T> implements Serializable{
|
|
|
|
|
|
/**
|
|
|
* 给msg赋值,连缀风格
|
|
|
+ *
|
|
|
* @param msg msg
|
|
|
* @return 对象自身
|
|
|
*/
|
|
@@ -90,6 +96,7 @@ public class CommonResult<T> implements Serializable{
|
|
|
|
|
|
/**
|
|
|
* 给data赋值,连缀风格
|
|
|
+ *
|
|
|
* @param data data
|
|
|
* @return 对象自身
|
|
|
*/
|
|
@@ -105,20 +112,32 @@ public class CommonResult<T> implements Serializable{
|
|
|
public static <T> CommonResult<T> ok() {
|
|
|
return new CommonResult<>(CODE_SUCCESS, "操作成功", null);
|
|
|
}
|
|
|
+
|
|
|
public static <T> CommonResult<T> ok(String msg) {
|
|
|
return new CommonResult<>(CODE_SUCCESS, msg, null);
|
|
|
}
|
|
|
+
|
|
|
public static <T> CommonResult<T> code(int code) {
|
|
|
return new CommonResult<>(code, null, null);
|
|
|
}
|
|
|
+
|
|
|
public static <T> CommonResult<T> data(T data) {
|
|
|
return new CommonResult<>(CODE_SUCCESS, "操作成功", data);
|
|
|
}
|
|
|
|
|
|
+ public static <T> CommonResult<T> fair(T data) {
|
|
|
+ return new CommonResult<>(CODE_SUCCESS, "操作失败", data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> CommonResult<T> result(boolean success, T data) {
|
|
|
+ return success ? data(data) : fair(data);
|
|
|
+ }
|
|
|
+
|
|
|
// 构建失败
|
|
|
public static <T> CommonResult<T> error() {
|
|
|
return new CommonResult<>(CODE_ERROR, "服务器异常", null);
|
|
|
}
|
|
|
+
|
|
|
public static <T> CommonResult<T> error(String msg) {
|
|
|
return new CommonResult<>(CODE_ERROR, msg, null);
|
|
|
}
|