You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
Java
72 lines
1.8 KiB
Java
3 years ago
|
package com.glxp.udidl.admin.util;
|
||
|
|
||
|
|
||
|
import com.glxp.udidl.admin.enums.ResultEnum;
|
||
|
import com.glxp.udidl.admin.res.BaseResponse;
|
||
|
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* 返回结果的操作类
|
||
|
*/
|
||
|
public class ResultVOUtils {
|
||
|
|
||
|
/**
|
||
|
* 成功时返回
|
||
|
* @param data 返回的data对象
|
||
|
* @return {@link BaseResponse}
|
||
|
*/
|
||
|
public static BaseResponse success(Object data) {
|
||
|
BaseResponse<Object> baseResponse = new BaseResponse<>();
|
||
|
baseResponse.setCode(20000);
|
||
|
baseResponse.setMessage("success");
|
||
|
baseResponse.setData(data);
|
||
|
return baseResponse;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 成功时返回
|
||
|
* @return {@link BaseResponse}
|
||
|
*/
|
||
|
public static BaseResponse success() {
|
||
|
Map data = new HashMap();
|
||
|
return success(data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 错误时返回
|
||
|
* @param code 错误码
|
||
|
* @param message 错误信息
|
||
|
* @return {@link BaseResponse}
|
||
|
*/
|
||
|
public static BaseResponse error(Integer code, String message) {
|
||
|
BaseResponse<Object> baseResponse = new BaseResponse<>();
|
||
|
baseResponse.setCode(code);
|
||
|
baseResponse.setMessage(message);
|
||
|
Map data = new HashMap();
|
||
|
baseResponse.setData(data);
|
||
|
return baseResponse;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 错误时返回
|
||
|
* @param resultEnum 错误枚举类
|
||
|
* @return {@link BaseResponse}
|
||
|
*/
|
||
|
public static BaseResponse error(ResultEnum resultEnum) {
|
||
|
return error(resultEnum.getCode(), resultEnum.getMessage());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 错误时返回
|
||
|
* @param resultEnum 错误枚举类
|
||
|
* @param message 错误的信息
|
||
|
* @return {@link BaseResponse}
|
||
|
*/
|
||
|
public static BaseResponse error(ResultEnum resultEnum, String message) {
|
||
|
return error(resultEnum.getCode(), message);
|
||
|
}
|
||
|
|
||
|
}
|