Commit c8ce4cae3fc9dbf7bf708f68ac285d4796fa3ba2
Committed by
Gitee
!1454 <code>selectJoinPage</code> 方法,支持带有排序参数的分页查询
Merge pull request !1454 from 光辉/master-jdk17-sortable-join
Showing
1 changed file
with
26 additions
and
3 deletions
yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java
| ... | ... | @@ -24,10 +24,10 @@ import java.util.Collection; |
| 24 | 24 | import java.util.List; |
| 25 | 25 | |
| 26 | 26 | /** |
| 27 | - * 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力 | |
| 27 | + * BaseMapperX 是一个泛型接口,继承自 MPJBaseMapper,用于提供一系列便捷的数据库操作方法。 | |
| 28 | + * 该接口主要包含分页查询、单条记录查询、多条记录查询、批量插入等常用操作。 | |
| 28 | 29 | * |
| 29 | - * 1. {@link BaseMapper} 为 MyBatis Plus 的基础接口,提供基础的 CRUD 能力 | |
| 30 | - * 2. {@link MPJBaseMapper} 为 MyBatis Plus Join 的基础接口,提供连表 Join 能力 | |
| 30 | + * @param <T> 实体类型 | |
| 31 | 31 | */ |
| 32 | 32 | public interface BaseMapperX<T> extends MPJBaseMapper<T> { |
| 33 | 33 | |
| ... | ... | @@ -68,6 +68,29 @@ public interface BaseMapperX<T> extends MPJBaseMapper<T> { |
| 68 | 68 | return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | + /** | |
| 72 | + * 执行分页查询并返回结果。 | |
| 73 | + * | |
| 74 | + * @param pageParam 分页参数,包含页码、每页条数和排序字段信息。如果 pageSize 为 {@link PageParam#PAGE_SIZE_NONE},则不分页,直接查询所有数据。 | |
| 75 | + * @param clazz 结果集的类类型 | |
| 76 | + * @param lambdaWrapper MyBatis Plus Join 查询条件包装器 | |
| 77 | + * @param <D> 结果集的泛型类型 | |
| 78 | + * @return 返回分页查询的结果,包括总记录数和当前页的数据列表 | |
| 79 | + */ | |
| 80 | + default <D> PageResult<D> selectJoinPage(SortablePageParam pageParam, Class<D> clazz, MPJLambdaWrapper<T> lambdaWrapper) { | |
| 81 | + // 特殊:不分页,直接查询全部 | |
| 82 | + if (PageParam.PAGE_SIZE_NONE.equals(pageParam.getPageSize())) { | |
| 83 | + List<D> list = selectJoinList(clazz, lambdaWrapper); | |
| 84 | + return new PageResult<>(list, (long) list.size()); | |
| 85 | + } | |
| 86 | + | |
| 87 | + // MyBatis Plus Join 查询 | |
| 88 | + IPage<D> mpPage = MyBatisUtils.buildPage(pageParam, pageParam.getSortingFields()); | |
| 89 | + mpPage = selectJoinPage(mpPage, clazz, lambdaWrapper); | |
| 90 | + // 转换返回 | |
| 91 | + return new PageResult<>(mpPage.getRecords(), mpPage.getTotal()); | |
| 92 | + } | |
| 93 | + | |
| 71 | 94 | default <DTO> PageResult<DTO> selectJoinPage(PageParam pageParam, Class<DTO> resultTypeClass, MPJBaseJoin<T> joinQueryWrapper) { |
| 72 | 95 | IPage<DTO> mpPage = MyBatisUtils.buildPage(pageParam); |
| 73 | 96 | selectJoinPage(mpPage, resultTypeClass, joinQueryWrapper); | ... | ... |