mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-03-22 21:39:01 +08:00
update 优化响应信息
This commit is contained in:
@@ -29,17 +29,6 @@ public class PageResult<T> implements Serializable {
|
||||
*/
|
||||
private List<T> rows;
|
||||
|
||||
/**
|
||||
* 分页
|
||||
*
|
||||
* @param list 列表数据
|
||||
* @param total 总记录数
|
||||
*/
|
||||
public PageResult(List<T> list, long total) {
|
||||
this.rows = list;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分页对象构建表格分页数据对象
|
||||
*/
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
package org.dromara.common.core.domain;
|
||||
|
||||
import org.dromara.common.core.constant.HttpStatus;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.dromara.common.core.constant.HttpStatus;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
|
||||
import static org.dromara.common.core.constant.HttpStatus.ERROR;
|
||||
import static org.dromara.common.core.constant.HttpStatus.SUCCESS;
|
||||
|
||||
/**
|
||||
* 响应信息主体
|
||||
*
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @author Lion Li
|
||||
*/
|
||||
@Data
|
||||
@@ -20,78 +24,152 @@ public class R<T> implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 成功
|
||||
* 响应状态码
|
||||
*/
|
||||
public static final int SUCCESS = 200;
|
||||
|
||||
/**
|
||||
* 失败
|
||||
*/
|
||||
public static final int FAIL = 500;
|
||||
|
||||
private int code;
|
||||
|
||||
/**
|
||||
* 响应提示信息
|
||||
*/
|
||||
private String msg;
|
||||
|
||||
/**
|
||||
* 响应业务数据
|
||||
*/
|
||||
private T data;
|
||||
|
||||
/**
|
||||
* 构建成功响应结果
|
||||
*
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 成功响应结果对象
|
||||
*/
|
||||
public static <T> R<T> ok() {
|
||||
return restResult(null, SUCCESS, "操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功响应结果(带业务数据)
|
||||
*
|
||||
* @param data 业务数据
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 成功响应结果对象
|
||||
*/
|
||||
public static <T> R<T> ok(T data) {
|
||||
return restResult(data, SUCCESS, "操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功响应结果(自定义提示信息)
|
||||
*
|
||||
* @param msg 自定义提示信息
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 成功响应结果对象
|
||||
*/
|
||||
public static <T> R<T> ok(String msg) {
|
||||
return restResult(null, SUCCESS, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功响应结果(自定义提示信息+业务数据)
|
||||
*
|
||||
* @param msg 自定义提示信息
|
||||
* @param data 业务数据
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 成功响应结果对象
|
||||
*/
|
||||
public static <T> R<T> ok(String msg, T data) {
|
||||
return restResult(data, SUCCESS, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建失败响应结果
|
||||
*
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 失败响应结果对象
|
||||
*/
|
||||
public static <T> R<T> fail() {
|
||||
return restResult(null, FAIL, "操作失败");
|
||||
return restResult(null, ERROR, "操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建失败响应结果(自定义提示信息)
|
||||
*
|
||||
* @param msg 自定义提示信息
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 失败响应结果对象
|
||||
*/
|
||||
public static <T> R<T> fail(String msg) {
|
||||
return restResult(null, FAIL, msg);
|
||||
return restResult(null, ERROR, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建失败响应结果(带业务数据)
|
||||
*
|
||||
* @param data 业务数据
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 失败响应结果对象
|
||||
*/
|
||||
public static <T> R<T> fail(T data) {
|
||||
return restResult(data, FAIL, "操作失败");
|
||||
return restResult(data, ERROR, "操作失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建失败响应结果(自定义提示信息+业务数据)
|
||||
*
|
||||
* @param msg 自定义提示信息
|
||||
* @param data 业务数据
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 失败响应结果对象
|
||||
*/
|
||||
public static <T> R<T> fail(String msg, T data) {
|
||||
return restResult(data, FAIL, msg);
|
||||
return restResult(data, ERROR, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建失败响应结果(自定义状态码+提示信息)
|
||||
*
|
||||
* @param code 自定义状态码
|
||||
* @param msg 自定义提示信息
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 失败响应结果对象
|
||||
*/
|
||||
public static <T> R<T> fail(int code, String msg) {
|
||||
return restResult(null, code, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回警告消息
|
||||
* 构建警告响应结果
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @return 警告消息
|
||||
* @param msg 自定义提示信息
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 警告响应结果对象
|
||||
*/
|
||||
public static <T> R<T> warn(String msg) {
|
||||
return restResult(null, HttpStatus.WARN, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回警告消息
|
||||
* 构建警告响应结果(自定义提示信息+业务数据)
|
||||
*
|
||||
* @param msg 返回内容
|
||||
* @param data 数据对象
|
||||
* @return 警告消息
|
||||
* @param msg 自定义提示信息
|
||||
* @param data 业务数据
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 警告响应结果对象
|
||||
*/
|
||||
public static <T> R<T> warn(String msg, T data) {
|
||||
return restResult(data, HttpStatus.WARN, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 核心构建方法
|
||||
*
|
||||
* @param data 业务数据
|
||||
* @param code 响应状态码
|
||||
* @param msg 提示信息
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return 响应结果对象
|
||||
*/
|
||||
private static <T> R<T> restResult(T data, int code, String msg) {
|
||||
R<T> r = new R<>();
|
||||
r.setCode(code);
|
||||
@@ -100,11 +178,26 @@ public class R<T> implements Serializable {
|
||||
return r;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断响应结果是否为失败
|
||||
*
|
||||
* @param ret 响应结果对象
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return true=失败,false=成功
|
||||
*/
|
||||
public static <T> Boolean isError(R<T> ret) {
|
||||
return !isSuccess(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断响应结果是否为成功
|
||||
*
|
||||
* @param ret 响应结果对象
|
||||
* @param <T> 响应数据的泛型类型
|
||||
* @return true=成功,false=失败
|
||||
*/
|
||||
public static <T> Boolean isSuccess(R<T> ret) {
|
||||
return R.SUCCESS == ret.getCode();
|
||||
return SUCCESS == ret.getCode();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
|
||||
wrapper.eq(FlowDefinition::getIsPublish, PublishStatus.PUBLISHED.getKey());
|
||||
Page<FlowDefinition> page = flowDefinitionMapper.selectPage(pageQuery.build(), wrapper);
|
||||
List<FlowDefinitionVo> list = BeanUtil.copyToList(page.getRecords(), FlowDefinitionVo.class);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
return PageResult.build(list, page.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ public class FlwDefinitionServiceImpl implements IFlwDefinitionService {
|
||||
wrapper.in(FlowDefinition::getIsPublish, Arrays.asList(PublishStatus.UNPUBLISHED.getKey(), PublishStatus.EXPIRED.getKey()));
|
||||
Page<FlowDefinition> page = flowDefinitionMapper.selectPage(pageQuery.build(), wrapper);
|
||||
List<FlowDefinitionVo> list = BeanUtil.copyToList(page.getRecords(), FlowDefinitionVo.class);
|
||||
return new PageResult<>(list, page.getTotal());
|
||||
return PageResult.build(list, page.getTotal());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user