|
@@ -6,6 +6,7 @@ import lombok.Data;
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
import java.io.Serializable;
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
|
/**
|
|
|
* 通用返回类
|
|
@@ -21,11 +22,12 @@ public class Result<T> implements Serializable {
|
|
|
public static int CODE_SUCCESS = 0;
|
|
|
public static int CODE_FAILURE = -1;
|
|
|
public static String[] NOOP = new String[]{};
|
|
|
+ public static LocalDateTime dataTime = LocalDateTime.now();
|
|
|
|
|
|
/**
|
|
|
* 处理状态:0: 成功, 1: 失败
|
|
|
*/
|
|
|
- @ApiModelProperty(value = "处理状态:0: 成功, 1: 失败", name = "code")
|
|
|
+ @ApiModelProperty(value = "处理状态:0: 成功, -1: 失败", name = "code")
|
|
|
private int code;
|
|
|
/**
|
|
|
* 消息
|
|
@@ -37,6 +39,9 @@ public class Result<T> implements Serializable {
|
|
|
*/
|
|
|
@ApiModelProperty(value = "返回数据", name = "data")
|
|
|
private T data;
|
|
|
+
|
|
|
+ @ApiModelProperty(value = "时间戳", name = "timestamp")
|
|
|
+ private LocalDateTime timestamp;
|
|
|
/**
|
|
|
* 处理成功,并返回数据
|
|
|
*
|
|
@@ -44,7 +49,7 @@ public class Result<T> implements Serializable {
|
|
|
* @return data
|
|
|
*/
|
|
|
public static Result success(Object data) {
|
|
|
- return new Result(CODE_SUCCESS, SUCCESS_MSG, data);
|
|
|
+ return new Result(CODE_SUCCESS, SUCCESS_MSG, data, dataTime);
|
|
|
}
|
|
|
/**
|
|
|
* 处理成功
|
|
@@ -52,7 +57,7 @@ public class Result<T> implements Serializable {
|
|
|
* @return data
|
|
|
*/
|
|
|
public static Result success() {
|
|
|
- return new Result(CODE_SUCCESS, SUCCESS_MSG, NOOP);
|
|
|
+ return new Result(CODE_SUCCESS, SUCCESS_MSG, NOOP, dataTime);
|
|
|
}
|
|
|
/**
|
|
|
* 处理成功
|
|
@@ -61,7 +66,7 @@ public class Result<T> implements Serializable {
|
|
|
* @return data
|
|
|
*/
|
|
|
public static Result success(String msg) {
|
|
|
- return new Result(CODE_SUCCESS, msg, NOOP);
|
|
|
+ return new Result(CODE_SUCCESS, msg, NOOP, dataTime);
|
|
|
}
|
|
|
/**
|
|
|
* 处理成功
|
|
@@ -71,7 +76,7 @@ public class Result<T> implements Serializable {
|
|
|
* @return data
|
|
|
*/
|
|
|
public static Result success(String msg, Object data) {
|
|
|
- return new Result(CODE_SUCCESS, msg, data);
|
|
|
+ return new Result(CODE_SUCCESS, msg, data, dataTime);
|
|
|
}
|
|
|
/**
|
|
|
* 处理失败,并返回数据(一般为错误信息)
|
|
@@ -81,7 +86,7 @@ public class Result<T> implements Serializable {
|
|
|
* @return data
|
|
|
*/
|
|
|
public static Result failure(int code, String msg) {
|
|
|
- return new Result(code, msg, NOOP);
|
|
|
+ return new Result(code, msg, NOOP , dataTime);
|
|
|
}
|
|
|
/**
|
|
|
* 处理失败
|
|
@@ -96,6 +101,6 @@ public class Result<T> implements Serializable {
|
|
|
@Override
|
|
|
public String toString() {
|
|
|
return "JsonResult [code=" + code + ", msg=" + msg + ", data="
|
|
|
- + data + "]";
|
|
|
+ + data + ", timestamp="+ dataTime + "]";
|
|
|
}
|
|
|
}
|