提交 7b60fd6c authored 作者: liupengfei's avatar liupengfei

扩展 ifPresent 方法,解决 调用 client 结果首先判断代码重复

上级 37955485
......@@ -7,9 +7,11 @@ import java.io.Serializable;
import java.util.Date;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.alibaba.fastjson.annotation.JSONField;
import com.zrqx.core.enums.ResponseCodeEnum;
import com.zrqx.core.exception.BaseException;
@ApiModel("响应报文")
public class CallBack<T> implements Serializable {
......@@ -135,6 +137,21 @@ public class CallBack<T> implements Serializable {
return !this.isStatus() || this.data == null;
}
public void ifPresent(Consumer<T> consumer) {
this.ifPresentThrowBaseException(consumer, null);
}
public void ifPresentThrowBaseException(Consumer<T> consumer, Supplier<BaseException> supplier) {
if (this.hasEntity()) {
consumer.accept(this.data);
} else {
if (supplier != null) {
BaseException exception = supplier.get();
throw exception;
}
}
}
public void setData(T data) {
this.data = data;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论