漯河市郾城区网站建设,滕州手机网站建设案例,注册城乡规划师报考条件2022,什么网站做的号介绍
方法 convertToIPage 用于将一个 List 转换为 IPage#xff0c;并在方法内部计算总数和总页数。该方法利用了 MyBatis-Plus 框架提供的 IPage 接口#xff0c;并采用泛型 T#xff0c;使其能够兼容任意类型的数据。
package com.util;import com.baomidou.my…介绍
方法 convertToIPage 用于将一个 List 转换为 IPage并在方法内部计算总数和总页数。该方法利用了 MyBatis-Plus 框架提供的 IPage 接口并采用泛型 T使其能够兼容任意类型的数据。
package com.util;import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;import java.util.List;public class PageUtils {/*** 转换为分页** param page 分页参数* param list 数据列表* param T 任意类型* return IPage 分页对象*/public static T IPageT convertToIPage(PageT page, ListT list) {// 获取数据列表总数int total list.size();// 获取当前页码long current page.getCurrent();// 获取每页显示的数据条数long size page.getSize();// 计算总页数long pages (long) Math.ceil((double) total / size);// 计算当前页的起始索引int startIndex (int) ((current - 1) * size);// 计算当前页的结束索引int endIndex Math.min((int) (current * size), total);// 截取对应页的数据ListT records list.subList(startIndex, endIndex);// 创建 IPage 对象并设置相关属性IPageT iPage new Page();iPage.setRecords(records);iPage.setTotal(total);iPage.setSize(size);iPage.setCurrent(page.getCurrent());iPage.setPages(pages);return iPage;}}