refactor: 分页响应数据结构调整
This commit is contained in:
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>com.youlai</groupId>
|
||||
<artifactId>youlai-boot</artifactId>
|
||||
<version>4.0.0</version>
|
||||
<version>4.1.0</version>
|
||||
<description>基于 Java 17 + SpringBoot 4 + Spring Security 构建的权限管理系统。</description>
|
||||
|
||||
<parent>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.youlai.boot.core.web;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@@ -21,13 +20,7 @@ public class PageResult<T> implements Serializable {
|
||||
|
||||
private String msg;
|
||||
|
||||
private List<T> data;
|
||||
|
||||
/**
|
||||
* 分页元信息;非分页接口不显示此字段
|
||||
*/
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private Page page;
|
||||
private PageData<T> data;
|
||||
|
||||
/**
|
||||
* 构建分页结果(MyBatis-Plus {@link IPage})。
|
||||
@@ -43,13 +36,10 @@ public class PageResult<T> implements Serializable {
|
||||
(page == null || page.getRecords() == null)
|
||||
? Collections.emptyList()
|
||||
: page.getRecords();
|
||||
result.setData(records);
|
||||
|
||||
Page pageMeta = new Page();
|
||||
pageMeta.setPageNum(page != null ? page.getCurrent() : 1L);
|
||||
pageMeta.setPageSize(page != null ? page.getSize() : 0L);
|
||||
pageMeta.setTotal(page != null ? page.getTotal() : 0L);
|
||||
result.setPage(pageMeta);
|
||||
PageData<T> pageData = new PageData<>();
|
||||
pageData.setList(records);
|
||||
pageData.setTotal(page != null ? page.getTotal() : 0L);
|
||||
result.setData(pageData);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -63,17 +53,17 @@ public class PageResult<T> implements Serializable {
|
||||
PageResult<T> result = new PageResult<>();
|
||||
result.setCode(ResultCode.SUCCESS.getCode());
|
||||
result.setMsg(ResultCode.SUCCESS.getMsg());
|
||||
result.setData(list != null ? list : Collections.emptyList());
|
||||
result.setPage(null);
|
||||
PageData<T> pageData = new PageData<>();
|
||||
pageData.setList(list != null ? list : Collections.emptyList());
|
||||
pageData.setTotal(0L);
|
||||
result.setData(pageData);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Page {
|
||||
public static class PageData<T> {
|
||||
|
||||
private long pageNum;
|
||||
|
||||
private long pageSize;
|
||||
private List<T> list;
|
||||
|
||||
private long total;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class RoleController {
|
||||
}
|
||||
|
||||
@Operation(summary = "获取角色的菜单ID集合")
|
||||
@GetMapping("/{roleId}/menuIds")
|
||||
@GetMapping("/{roleId}/menu-ids")
|
||||
public Result<List<Long>> getRoleMenuIds(
|
||||
@Parameter(description = "角色ID") @PathVariable Long roleId
|
||||
) {
|
||||
|
||||
@@ -149,8 +149,8 @@ const contentConfig = reactive({
|
||||
// 数据解析函数
|
||||
parseData(res) {
|
||||
return {
|
||||
total: res?.page?.total ?? 0,
|
||||
list: res?.data ?? [],
|
||||
total: res?.total ?? 0,
|
||||
list: res?.list ?? [],
|
||||
};
|
||||
},
|
||||
// 分页配置
|
||||
|
||||
@@ -314,9 +314,9 @@
|
||||
function handleQuery() {
|
||||
loading.value = true;
|
||||
${entityName}API.getPage(queryParams)
|
||||
.then((res) => {
|
||||
pageData.value = res.data;
|
||||
total.value = res.page?.total ?? 0;
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total ?? 0;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
|
||||
@@ -315,9 +315,9 @@
|
||||
function handleQuery() {
|
||||
loading.value = true;
|
||||
${entityName}API.getPage(queryParams)
|
||||
.then((res) => {
|
||||
pageData.value = res.data;
|
||||
total.value = res.page?.total ?? 0;
|
||||
.then((data) => {
|
||||
pageData.value = data.list;
|
||||
total.value = data.total ?? 0;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
|
||||
Reference in New Issue
Block a user