package com.iailab.sdk.auth.client.common.pojo;
|
|
import com.iailab.sdk.auth.client.common.exception.ErrorCode;
|
import com.iailab.sdk.auth.client.common.exception.enums.GlobalErrorCodeConstants;
|
import lombok.Data;
|
|
import java.io.Serializable;
|
|
/**
|
* 通用返回
|
*
|
* @param <T> 数据泛型
|
*/
|
@Data
|
public class CommonResult<T> implements Serializable {
|
|
/**
|
* 错误码
|
*
|
* @see ErrorCode#getCode()
|
*/
|
private Integer code;
|
/**
|
* 返回数据
|
*/
|
private T data;
|
/**
|
* 错误提示,用户可阅读
|
*
|
* @see ErrorCode#getMsg() ()
|
*/
|
private String msg;
|
|
public static <T> CommonResult<T> error(Integer code, String message) {
|
CommonResult<T> result = new CommonResult<>();
|
result.code = code;
|
result.msg = message;
|
return result;
|
}
|
|
public static <T> CommonResult<T> error(ErrorCode errorCode) {
|
return error(errorCode.getCode(), errorCode.getMsg());
|
}
|
|
public static <T> CommonResult<T> success(T data) {
|
CommonResult<T> result = new CommonResult<>();
|
result.code = GlobalErrorCodeConstants.SUCCESS.getCode();
|
result.data = data;
|
result.msg = "";
|
return result;
|
}
|
|
|
|
}
|