开始分页

@param pageNum      页码
@param pageSize     每页显示数量
@param count        是否进行count查询
@param reasonable   分页合理化,null时用默认配置
@param pageSizeZero true且pageSize=0时返回全部结果，false时分页,null时用默认配置
961454
public static <E> Page<E> startPage(int pageNum, int pageSize, boolean count, Boolean reasonable, Boolean pageSizeZero) {
        Page<E> page = new Page<E>(pageNum, pageSize, count);
        page.setReasonable(reasonable);
        page.setPageSizeZero(pageSizeZero);
        //当已经执行过orderBy的时候
        Page<E> oldPage = getLocalPage();
        if (oldPage != null && oldPage.isOrderByOnly()) {
            page.setOrderBy(oldPage.getOrderBy());
        }
        setLocalPage(page);
        return page;
    }
538698
public static int size(String size, int defaultValue) {
        int parseInt = NumUtils.intVal(size, defaultValue);
        return parseInt <= 0 ? defaultValue
                : (parseInt > DEFAULT_MAX_PAGE_SIZE ? DEFAULT_MAX_PAGE_SIZE : parseInt);
    }
550145
public static synchronized int getPageSize() throws OperatingSystemException {
        if (cachedPageSize == -1) {
            switch (instance().getOperatingSystemType()) {
                case AIX:
                case HPUX:
                case IBMi:
                case Linux:
                case Mac:
                case Solaris:
                case zOS:
                    cachedPageSize = getPageSizePOSIX();
                    break;
                default:
                    throw new OperatingSystemException(Tr.formatMessage(tc, "os.pagesize.unavailable"));
            }
        }
        return cachedPageSize;
    }
953494
@Override
  public void writePage(int pageID, P page) {
    try {
      countWrite();
      byte[] array = pageToByteArray(page);
      long offset = ((long) (header.getReservedPages() + pageID)) * (long) pageSize;
      assert offset >= 0 : header.getReservedPages() + " " + pageID + " " + pageSize + " " + offset;
      file.seek(offset);
      file.write(array);
      page.setDirty(false);
    }
    catch(IOException e) {
      throw new RuntimeException("Error writing to page file.", e);
    }
  }
315614
public static  <E> List<E> pageQuery(Dialect dialect, Executor executor, MappedStatement ms, Object parameter,
                                 RowBounds rowBounds, ResultHandler resultHandler,
                                 BoundSql boundSql, CacheKey cacheKey) throws SQLException {
        //判断是否需要进行分页查询
        if (dialect.beforePage(ms, parameter, rowBounds)) {
            //生成分页的缓存 key
            CacheKey pageKey = cacheKey;
            //处理参数对象
            parameter = dialect.processParameterObject(ms, parameter, boundSql, pageKey);
            //调用方言获取分页 sql
            String pageSql = dialect.getPageSql(ms, boundSql, parameter, rowBounds, pageKey);
            BoundSql pageBoundSql = new BoundSql(ms.getConfiguration(), pageSql, boundSql.getParameterMappings(), parameter);

            Map<String, Object> additionalParameters = getAdditionalParameter(boundSql);
            //设置动态参数
            for (String key : additionalParameters.keySet()) {
                pageBoundSql.setAdditionalParameter(key, additionalParameters.get(key));
            }
            //执行分页查询
            return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, pageKey, pageBoundSql);
        } else {
            //不执行分页的情况下，也不执行内存分页
            return executor.query(ms, parameter, RowBounds.DEFAULT, resultHandler, cacheKey, boundSql);
        }
    }
391414
public function listData($list, $page = 1, $size = 10)
    {
        $reData['totalPages'] = (int)$list->lastPage();
        $reData['totalCount'] = (int)$list->total();
        $reData['page'] = (int)$page;
        $reData['limit'] = (int)$size;
        $reData['count'] = (int)$list->count();

        if ($page == 1) {
            $reData['firstPage'] = true; //是否为首页
            $reData['hasPrePage'] = false; //是否有上一页
            $reData['prePage'] = 0; //上一页的页数
            if ($reData['totalPages'] == 1) {
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['nextPage'] = 0;
            } else {
                $reData['hasNextPage'] = true; //是否有下一页
                $reData['nextPage'] = 2; //下一页的页数
            }
        } else {
            $reData['firstPage'] = false; //是否为首页
            if ($reData['totalPages'] == 1) {
                $reData['hasPrePage'] = false; //是否有上一页
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['prePage'] = 1; //上一页的页数
                $reData['nextPage'] = 0; //下一页的页数
            } elseif ($page < $reData['totalPages']) {
                $reData['hasPrePage'] = true; //是否有上一页
                $reData['hasNextPage'] = true; //是否有下一页
                $reData['prePage'] = $page - 1; //上一页的页数
                $reData['nextPage'] = $page + 1; //下一页的页数
            } else {
                $reData['hasPrePage'] = true; //是否有上一页
                $reData['hasNextPage'] = false; //是否有下一页
                $reData['prePage'] = $page - 1; //上一页的页数
                $reData['nextPage'] = 0; //下一页的页数
            }
        }

        if ($page == $reData['totalPages']) {
            $reData['lastPage'] = true; //是否是最末页
        } else {
            $reData['lastPage'] = false; //是否是最末页
        }

        $reData['data'] = $list->toArray()['data'];

        return $reData;
    }
1160884
public static int getDefaultPageSize() {
        synchronized (sLock) {
            if (sDefaultPageSize == 0) {
                try {
                    Class clazz = Class.forName("android.os.StatFs");
                    Method m = clazz.getMethod("getBlockSize");
                    Object statFsObj = clazz.getConstructor(String.class).newInstance("/data");
                    Integer value = (Integer) m.invoke(statFsObj, (Object[])null);
                    if (value != null)
                        return value.intValue();
                } catch (Exception e) { }
            }
            if (sDefaultPageSize == 0)
                sDefaultPageSize = 1024;
            return sDefaultPageSize;
        }
    }
1291475
@Override
  public void deletePage(int pageID) {
    try {
      // / put id to empty nodes and
      // delete from cache
      super.deletePage(pageID);

      // delete from file
      countWrite();
      byte[] array = pageToByteArray(null);
      file.getRecordBuffer(pageID).put(array);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
1249869
public static PageRequest of(final int page, final int size) {
    return PageRequest.of(page, size, Sort.unsorted());
  }
862088
@Override
  public int count() {

    int listSize = getList().size();
    int pageSize = getPageSize();
    int pageCount = listSize / pageSize;

    pageCount += listSize % pageSize > 0 ? 1 : 0;

    return pageCount;
  }
835318
protected List<Integer> getPageSizes() {

        try {
            return Collections.singletonList(Integer.valueOf(m_configObject.getInt(JSON_KEY_PAGESIZE)));
        } catch (JSONException e) {
            List<Integer> result = null;
            String pageSizesString = null;
            try {
                pageSizesString = m_configObject.getString(JSON_KEY_PAGESIZE);
                String[] pageSizesArray = pageSizesString.split("-");
                if (pageSizesArray.length > 0) {
                    result = new ArrayList<>(pageSizesArray.length);
                    for (int i = 0; i < pageSizesArray.length; i++) {
                        result.add(Integer.valueOf(pageSizesArray[i]));
                    }
                }
                return result;
            } catch (NumberFormatException | JSONException e1) {
                LOG.warn(Messages.get().getBundle().key(Messages.LOG_PARSING_PAGE_SIZES_FAILED_1, pageSizesString), e);
            }
            if (null == m_baseConfig) {
                if (LOG.isInfoEnabled()) {
                    LOG.info(Messages.get().getBundle().key(Messages.LOG_NO_PAGESIZE_SPECIFIED_0), e);
                }
                return null;
            } else {
                return m_baseConfig.getPaginationConfig().getPageSizes();
            }
        }
    }
1333502
public void resetPageCount() {
        pageN = 0;
        DocListener listener;
		for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
            listener = (DocListener) iterator.next();
            listener.resetPageCount();
        }
    }
136447
public static long count(ISelect select) {
        Page<?> page = startPage(1, -1, true);
        select.doSelect();
        return page.getTotal();
    }
844979
public void setPage(int totalCount) {

        //
        // 缓存中的数据
        //
        page.put(FrontEndInterfaceConstant.PAGE_NO, ThreadContext.getContext(FrontEndInterfaceConstant.PAGE_NO));
        page.put(FrontEndInterfaceConstant.PAGE_SIZE, ThreadContext.getContext(FrontEndInterfaceConstant.PAGE_SIZE));
        page.put(FrontEndInterfaceConstant.PAGE_ORDER_BY,
                    ThreadContext.getContext(FrontEndInterfaceConstant.PAGE_ORDER_BY));
        page.put(FrontEndInterfaceConstant.PAGE_ORDER, ThreadContext.getContext(FrontEndInterfaceConstant.PAGE_ORDER));

        // 业务总数
        page.put(FrontEndInterfaceConstant.TOTAL_COUNT, totalCount);
    }
374439
public boolean setPageSize(Rectangle pageSize) {
        if (writer != null && writer.isPaused()) {
            return false;
        }
        nextPageSize = new Rectangle(pageSize);
        return true;
    }
1165003
def number_of_pages(self, key, value):
    """"""
    result = maybe_int(force_single_element(value.get('a', '')))
    if result and result > 0:
        return result
1311648
public Page<E> pageNum(int pageNum) {
        //分页合理化，针对不合理的页码自动处理
        this.pageNum = ((reasonable != null && reasonable) && pageNum <= 0) ? 1 : pageNum;
        return this;
    }