/* * Copyright 2026 mingliqiye * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ProjectName FastBaseMapper.kt * ModuleName mingli-utils.main * CurrentFile PageData.kt * LastUpdate 2026-10-26 23:22:18 * UpdateUser MingLiPro */ package com.mingliqiye.utils.http import com.baomidou.mybatisplus.extension.plugins.pagination.Page /** * 分页数据类 */ data class PageData( /** * 当前页的数据列表 */ val records: Collection = emptyList(), /** * 总条数(总记录数) */ val totalCount: Long = 0, /** * 总页数 */ val totalPages: Long = 0, /** * 每页大小 */ val pageSize: Long = 0, /** * 当前页码(从 1 开始) */ val pageIndex: Long = 0, ) { /** 伴生对象,提供工厂方法 */ companion object { /** * 从 MyBatis-Plus 的分页对象构建分页数据 * * @param T 记录类型 * @param page MyBatis-Plus 分页对象 * @return 转换后的分页数据 */ fun of(page: Page): PageData = PageData( records = page.records, totalCount = page.total, totalPages = page.pages, pageSize = page.size, pageIndex = page.current, ) } }