package com.pukka.jiecheng.utils; public class PageNumberUtil { /** * 计算总页数 * */ public static int calculateTotalPages(int totalItems, int pageSize) { if (totalItems <= 0) { return 0; // 没有数据时返回0页 } if (pageSize <= 0) { throw new IllegalArgumentException("每页大小必须大于0"); } return (totalItems - 1) / pageSize + 1; } /** * 计算当前页数 * @param position 当前position * @param itemsPerPage 每页项数 * */ public static int calculatePage(int position, int itemsPerPage) { return (position / itemsPerPage) + 1; } }