package com.kidgrow.common.base;
|
|
/**
|
* 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
|
*
|
* @Description: <br>
|
* @Project: <br>
|
* @CreateDate: Created in 2020/2/3 17:01 <br>
|
* @Author: <a href="4345453@kidgrow.com">liuke</a>
|
*/
|
public class ResponseBuilder {
|
/**
|
* 通用错误
|
*
|
* @param msg 响应消息
|
*/
|
public static <T> ApiResponse<T> buildResultError(String msg) {
|
return new ApiResponse<>(ResponseCode.ERROR, msg);
|
}
|
|
/**
|
* 错误响应
|
*
|
* @param code 错误代码,备选值参见 {@link ResponseCode}
|
* @param msg 响应消息
|
*/
|
public static <T> ApiResponse<T> buildResultError(Integer code, String msg) {
|
return new ApiResponse<>(code, msg);
|
}
|
|
/**
|
* 通用成功响应
|
*/
|
public static <T> ApiResponse<T> buildResultSuccess() {
|
return new ApiResponse<>(ResponseCode.SUCCESS, ResponseCode.SUCCESS_MSG);
|
}
|
|
/**
|
* 通用成功响应,带响应消息
|
*
|
* @param msg 响应消息
|
*/
|
public static <T> ApiResponse<T> buildResultSuccess(String msg) {
|
return new ApiResponse<>(ResponseCode.SUCCESS, msg);
|
}
|
|
/**
|
* 成功响应
|
*
|
* @param code 响应代码,备选值参见 {@link ResponseCode}
|
* @param msg 响应消息
|
* @param data 响应数据
|
*/
|
public static <T> ApiResponse<T> buildResult(Integer code, String msg, T data) {
|
ApiResponse<T> response = new ApiResponse<>(code, msg);
|
response.setData(data);
|
return response;
|
}
|
|
/**
|
* 成功响应
|
*
|
* @param data 响应数据
|
*/
|
public static <T> ApiResponse<T> buildResultSuccess(T data) {
|
return buildResult(ResponseCode.SUCCESS, ResponseCode.SUCCESS_MSG, data);
|
}
|
}
|