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