From 3a35b24476b8a0a8e7841f8d2d5b8d129a65dd95 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Wed, 11 Feb 2026 22:33:33 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=88=86=E9=A1=B5=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../com/youlai/boot/core/web/PageResult.java | 32 +++++++------------ .../system/controller/RoleController.java | 2 +- .../templates/codegen/index.curd.js.vue.vm | 4 +-- .../templates/codegen/index.js.vue.vm | 6 ++-- .../resources/templates/codegen/index.vue.vm | 6 ++-- 6 files changed, 21 insertions(+), 31 deletions(-) diff --git a/pom.xml b/pom.xml index 0663d1ca..8933c16c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.youlai youlai-boot - 4.0.0 + 4.1.0 基于 Java 17 + SpringBoot 4 + Spring Security 构建的权限管理系统。 diff --git a/src/main/java/com/youlai/boot/core/web/PageResult.java b/src/main/java/com/youlai/boot/core/web/PageResult.java index e97ba21b..8653cdd3 100644 --- a/src/main/java/com/youlai/boot/core/web/PageResult.java +++ b/src/main/java/com/youlai/boot/core/web/PageResult.java @@ -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 implements Serializable { private String msg; - private List data; - - /** - * 分页元信息;非分页接口不显示此字段 - */ - @JsonInclude(JsonInclude.Include.NON_NULL) - private Page page; + private PageData data; /** * 构建分页结果(MyBatis-Plus {@link IPage})。 @@ -43,13 +36,10 @@ public class PageResult 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 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 implements Serializable { PageResult result = new PageResult<>(); result.setCode(ResultCode.SUCCESS.getCode()); result.setMsg(ResultCode.SUCCESS.getMsg()); - result.setData(list != null ? list : Collections.emptyList()); - result.setPage(null); + PageData 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 { - private long pageNum; - - private long pageSize; + private List list; private long total; } diff --git a/src/main/java/com/youlai/boot/system/controller/RoleController.java b/src/main/java/com/youlai/boot/system/controller/RoleController.java index b442ad63..a6dfd9fc 100644 --- a/src/main/java/com/youlai/boot/system/controller/RoleController.java +++ b/src/main/java/com/youlai/boot/system/controller/RoleController.java @@ -102,7 +102,7 @@ public class RoleController { } @Operation(summary = "获取角色的菜单ID集合") - @GetMapping("/{roleId}/menuIds") + @GetMapping("/{roleId}/menu-ids") public Result> getRoleMenuIds( @Parameter(description = "角色ID") @PathVariable Long roleId ) { diff --git a/src/main/resources/templates/codegen/index.curd.js.vue.vm b/src/main/resources/templates/codegen/index.curd.js.vue.vm index 8e4bd380..fe944777 100644 --- a/src/main/resources/templates/codegen/index.curd.js.vue.vm +++ b/src/main/resources/templates/codegen/index.curd.js.vue.vm @@ -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 ?? [], }; }, // 分页配置 diff --git a/src/main/resources/templates/codegen/index.js.vue.vm b/src/main/resources/templates/codegen/index.js.vue.vm index 64aba46c..ca76214a 100644 --- a/src/main/resources/templates/codegen/index.js.vue.vm +++ b/src/main/resources/templates/codegen/index.js.vue.vm @@ -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; diff --git a/src/main/resources/templates/codegen/index.vue.vm b/src/main/resources/templates/codegen/index.vue.vm index 455dda3b..69c1258d 100644 --- a/src/main/resources/templates/codegen/index.vue.vm +++ b/src/main/resources/templates/codegen/index.vue.vm @@ -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;