package com.webmanage.common;
|
|
import lombok.Data;
|
|
/**
|
* 统一返回结果
|
*
|
* @author webmanage
|
* @date 2024-08-07
|
*/
|
@Data
|
public class Result<T> {
|
|
/**
|
* 状态码
|
*/
|
private Integer code;
|
|
/**
|
* 返回消息
|
*/
|
private String msg;
|
|
/**
|
* 返回数据
|
*/
|
private T data;
|
|
/**
|
* 时间戳
|
*/
|
private Long timestamp;
|
|
public Result() {
|
this.timestamp = System.currentTimeMillis();
|
}
|
|
public Result(Integer code, String msg) {
|
this();
|
this.code = code;
|
this.msg = msg;
|
}
|
|
public Result(Integer code, String msg, T data) {
|
this(code, msg);
|
this.data = data;
|
}
|
|
/**
|
* 成功返回
|
*/
|
public static <T> Result<T> success() {
|
return new Result<>(200, "操作成功");
|
}
|
|
/**
|
* 成功返回
|
*/
|
public static <T> Result<T> success(String msg) {
|
return new Result<>(200, msg);
|
}
|
|
/**
|
* 成功返回
|
*/
|
public static <T> Result<T> success(T data) {
|
return new Result<>(200, "操作成功", data);
|
}
|
|
/**
|
* 成功返回
|
*/
|
public static <T> Result<T> success(String msg, T data) {
|
return new Result<>(200, msg, data);
|
}
|
|
/**
|
* 失败返回
|
*/
|
public static <T> Result<T> error() {
|
return new Result<>(500, "操作失败");
|
}
|
|
/**
|
* 失败返回
|
*/
|
public static <T> Result<T> error(String msg) {
|
return new Result<>(500, msg);
|
}
|
|
/**
|
* 失败返回
|
*/
|
public static <T> Result<T> error(Integer code, String msg) {
|
return new Result<>(code, msg);
|
}
|
}
|