cn.woodwhales.common.model.result.OpResult Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of woodwhales-common Show documentation
Show all versions of woodwhales-common Show documentation
https://github.com/woodwhales
package cn.woodwhales.common.model.result;
import cn.woodwhales.common.model.enums.RespCodeEnum;
import java.util.Objects;
/**
* 业务数据响应体
*
* @author: woodwhales on 2020-09-18 22:05
*
*/
public class OpResult {
/**
* 通用基础响应结果对象
*/
private BaseRespResult baseRespResult;
/**
* 业务数据
*/
private T data;
public static OpResult success(T data) {
return new OpResult(RespCodeEnum.SUCCESS, data);
}
public static OpResult success() {
return new OpResult(RespCodeEnum.SUCCESS, null);
}
public static OpResult failure() {
return new OpResult(RespCodeEnum.ERROR, null);
}
public static OpResult failure(BaseRespResult baseRespResult) {
return new OpResult(baseRespResult, null);
}
public static OpResult failure(BaseRespResult baseRespResult, T data) {
return new OpResult(baseRespResult, data);
}
/**
* 获取数据对象
* @return 数据对象
*/
public T getData() {
return data;
}
/**
* 获取响应状态码对象
* @return 响应状态码对象
*/
public BaseRespResult getBaseRespResult() {
return baseRespResult;
}
/**
* 数据是否为空
* @return 数据是否为空
*/
public boolean dataIsNull() {
return Objects.isNull(data);
}
/**
* 数据是否不为空
* @return 数据是否不为空
*/
public boolean dataIsNonNull() {
return Objects.nonNull(data);
}
/**
* 是否响应成功
* @return 是否响应成功
*/
public boolean isSuccessful() {
return Objects.equals(baseRespResult.getCode(), RespCodeEnum.SUCCESS.getCode());
}
/**
* 是否响应失败
* @return 是否响应失败
*/
public boolean isFailure() {
return !isSuccessful();
}
private OpResult() {
}
private OpResult(BaseRespResult baseRespResult, T data) {
this.baseRespResult = baseRespResult;
this.data = data;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy