jpa 的分页类org.springframework.data.domain.Page<T>

本文介绍了Spring Data项目中Page接口的功能与实现细节,包括如何获取当前页码、页面大小、总页数等信息,以及如何判断是否存在前一页或后一页。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

package org.springframework.data.domain;

import java.util.Iterator;
import java.util.List;

/**
 * A page is a sublist of a list of objects. It allows gain information about the position of it in the containing
 * entire list.
 *
 * @param <T>
 * @author Oliver Gierke
 */
public interface Page<T> extends Iterable<T> {

    /**
     * Returns the number of the current page. Is always non-negative and less that {@code Page#getTotalPages()}.
     *
     * @return the number of the current page
     */
    int getNumber();

    /**
     * Returns the size of the page.
     *
     * @return the size of the page
     */
    int getSize();

    /**
     * Returns the number of total pages.
     *
     * @return the number of toral pages
     */
    int getTotalPages();

    /**
     * Returns the number of elements currently on this page.
     *
     * @return the number of elements currently on this page
     */
    int getNumberOfElements();

    /**
     * Returns the total amount of elements.
     *
     * @return the total amount of elements
     */
    long getTotalElements();

    /**
     * Returns if there is a previous page.
     *
     * @return if there is a previous page
     */
    boolean hasPreviousPage();

    /**
     * Returns whether the current page is the first one.
     *
     * @return
     */
    boolean isFirstPage();

    /**
     * Returns if there is a next page.
     *
     * @return if there is a next page
     */
    boolean hasNextPage();

    /**
     * Returns whether the current page is the last one.
     *
     * @return
     */
    boolean isLastPage();

    /**
     * Returns the {@link Pageable} to request the next {@link Page}. Can be {@literal null} in case the current
     * {@link Page} is already the last one. Clients should check {@link #hasNextPage()} before calling this method to
     * make sure they receive a non-{@literal null} value.
     *
     * @return
     */
    Pageable nextPageable();

    /**
     * Returns the {@link Pageable} to request the previous page. Can be {@literal null} in case the current {@link Page}
     * is already the first one. Clients should check {@link #hasPreviousPage()} before calling this method make sure
     * receive a non-{@literal null} value.
     *
     * @return
     */
    Pageable previousPageable();

    /*
     * (non-Javadoc)
     * @see java.lang.Iterable#iterator()
     */
    Iterator<T> iterator();

    /**
     * Returns the page content as {@link List}.
     *
     * @return
     */
    List<T> getContent();

    /**
     * Returns whether the {@link Page} has content at all.
     *
     * @return
     */
    boolean hasContent();

    /**
     * Returns the sorting parameters for the page.
     *
     * @return
     */
    Sort getSort();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值