Skip to content

Commit

Permalink
feature: 增加静态方法,用于创建 Result 实例
Browse files Browse the repository at this point in the history
  • Loading branch information
myoss committed Nov 11, 2020
1 parent d5c9d98 commit 60fca91
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,50 @@ public Object getExtraInfo(String key) {
public String toString() {
return JsonApi.toJson(this);
}

/**
* 创建成功的返回值
*
* @param <T> 泛型
* @return Result 实例
*/
public static <T> Result<T> ok() {
return new Result<>();
}

/**
* 创建成功的返回值
*
* @param value 结果值
* @param <T> 泛型
* @return Result 实例
*/
public static <T> Result<T> ok(T value) {
return new Result<>(value);
}

/**
* 创建失败的返回值
*
* @param <T> 泛型
* @return Result 实例
*/
public static <T> Result<T> fail() {
Result<T> result = new Result<>();
result.setSuccess(false);
return result;
}

/**
* 创建失败的返回值
*
* @param value 结果值
* @param <T> 泛型
* @return Result 实例
*/
public static <T> Result<T> fail(T value) {
Result<T> result = new Result<>(value);
result.setSuccess(false);
return result;
}
}

0 comments on commit 60fca91

Please sign in to comment.