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.
87 lines
2.2 KiB
Java
87 lines
2.2 KiB
Java
package com.glxp.udidl.admin.util;
|
|
|
|
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.glxp.udidl.admin.enums.ResultEnum;
|
|
import com.glxp.udidl.admin.res.BaseResponse;
|
|
import com.glxp.udidl.admin.res.PageSimpleResponse;
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
public static BaseResponse page(PageInfo pageInfo) {
|
|
PageSimpleResponse pageSimpleResponse = new PageSimpleResponse();
|
|
pageSimpleResponse.setList(pageInfo.getList());
|
|
pageSimpleResponse.setTotal(pageInfo.getTotal());
|
|
return success(pageSimpleResponse);
|
|
}
|
|
|
|
}
|