-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ResultHelper操作ResultModel,ApiResultHelper操作ApiResultModel;并写了测试
- Loading branch information
Showing
9 changed files
with
288 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/com/fengwenyi/api_result/helper/ApiResultHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.fengwenyi.api_result.helper; | ||
|
||
import com.fengwenyi.api_result.model.ApiResultModel; | ||
|
||
/** | ||
* 接口结果返回封装帮助工具类 | ||
* | ||
* <p> | ||
* 该工具类操作的实体类是:{@link com.fengwenyi.api_result.model.ApiResultModel} | ||
* </p> | ||
* | ||
* <p> | ||
* 我们提供了如下三个方法: | ||
* </p> | ||
* | ||
* <ul> | ||
* <li>success(S code, String message, T data):成功,并返回的数据的方法</li> | ||
* <li>success(S code, String message):成功,不返回数据</li> | ||
* <li>error(S code, String message):失败</li> | ||
* </ul> | ||
* | ||
* @author Erwin Feng | ||
* @since 2019-08-21 10:47 | ||
*/ | ||
public class ApiResultHelper { | ||
|
||
/** | ||
* 成功,并返回数据 | ||
* @param code 返回码 | ||
* @param message 描述信息 | ||
* @param data 数据 | ||
* @param <S> 返回码类型 | ||
* @param <T> 数据类型 | ||
* @return 返回结果封装 {@link ApiResultModel} | ||
*/ | ||
public static <S, T> ApiResultModel<S, T> success(S code, String message, T data) { | ||
return new ApiResultModel<>(code, message, data); | ||
} | ||
|
||
/** | ||
* 成功,无数据返回 | ||
* @param code 返回码 | ||
* @param message 描述信息 | ||
* @param <S> 返回码类型 | ||
* @param <T> 数据类型 | ||
* @return 返回结果封装 {@link ApiResultModel} | ||
*/ | ||
public static <S, T> ApiResultModel<S, T> success(S code, String message) { | ||
return new ApiResultModel<>(code, message, null); | ||
} | ||
|
||
/** | ||
* 失败,无数据返回 | ||
* @param code 返回码 | ||
* @param message 描述信息 | ||
* @param <S> 返回码类型 | ||
* @param <T> 数据类型 | ||
* @return 返回结果封装 {@link ApiResultModel} | ||
*/ | ||
public static <S, T> ApiResultModel<S, T> error(S code, String message) { | ||
return new ApiResultModel<>(code, message); | ||
} | ||
|
||
} |
44 changes: 26 additions & 18 deletions
44
src/main/java/com/fengwenyi/api_result/helper/ResultHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,57 @@ | ||
package com.fengwenyi.api_result.helper; | ||
|
||
import com.fengwenyi.api_result.model.ApiResultModel; | ||
import com.fengwenyi.api_result.model.ResultModel; | ||
|
||
/** | ||
* 结果返回 | ||
* 结果返回封装帮助工具类 | ||
* | ||
* <p> | ||
* 该工具类操作的实体类是:{@link com.fengwenyi.api_result.model.ResultModel} | ||
* </p> | ||
* | ||
* <p> | ||
* 我们提供了如下三个方法: | ||
* </p> | ||
* | ||
* <ul> | ||
* <li>success(String message, T data):成功,并返回的数据的方法</li> | ||
* <li>success(String message):成功,不返回数据</li> | ||
* <li>error(String message):失败</li> | ||
* </ul> | ||
* | ||
* @author Erwin Feng | ||
* @since 2019-08-02 18:14 | ||
*/ | ||
public class ResultHelper { | ||
|
||
/** | ||
* 成功,并返回数据 | ||
* @param code 返回码 | ||
* @param message 描述信息 | ||
* @param data 数据 | ||
* @param <S> 返回码类型 | ||
* @param <T> 数据类型 | ||
* @return 返回结果封装 {@link com.fengwenyi.api_result.model.ApiResultModel} | ||
* @return 返回结果封装 {@link com.fengwenyi.api_result.model.ResultModel} | ||
*/ | ||
public static <S, T> ApiResultModel<S, T> success(S code, String message, T data) { | ||
return new ApiResultModel<>(code, message, data); | ||
public static <T> ResultModel<T> success(String message, T data) { | ||
return new ResultModel<>(message, data); | ||
} | ||
|
||
/** | ||
* 成功,无数据返回 | ||
* @param code 返回码 | ||
* @param message 描述信息 | ||
* @param <S> 返回码类型 | ||
* @param <T> 数据类型 | ||
* @return 返回结果封装 {@link com.fengwenyi.api_result.model.ApiResultModel} | ||
* @return 返回结果封装 {@link com.fengwenyi.api_result.model.ResultModel} | ||
*/ | ||
public static <S, T> ApiResultModel<S, T> success(S code, String message) { | ||
return new ApiResultModel<>(code, message, null); | ||
public static <T> ResultModel<T> success(String message) { | ||
return new ResultModel<>(message, null); | ||
} | ||
|
||
/** | ||
* 失败,无数据返回 | ||
* @param code 返回码 | ||
* @param message 描述信息 | ||
* @param <S> 返回码类型 | ||
* @param <T> 数据类型 | ||
* @return 返回结果封装 {@link com.fengwenyi.api_result.model.ApiResultModel} | ||
* @return 返回结果封装 {@link com.fengwenyi.api_result.model.ResultModel} | ||
*/ | ||
public static <S, T> ApiResultModel<S, T> error(S code, String message) { | ||
return new ApiResultModel<>(code, message); | ||
public static <T> ResultModel<T> error(String message) { | ||
return new ResultModel<>(message); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.