Pageable is the request side of Spring Data pagination: it carries the page index, page size and sort order you pass to a repository method. Page<T> is the response side: it holds the items of one page plus metadata such as the total number of elements and total pages. Together they let you return a slice of a large result set instead of the whole table.
Both live in org.springframework.data.domain and work the same way for JPA, JDBC, MongoDB and other Spring Data modules.
| Type | Direction | Contains |
|---|---|---|
Pageable | Input | Page number (zero-based), page size, Sort |
Page<T> | Output | Content, total elements, total pages, current page info |
Slice<T> | Output | Content and whether a next slice exists, no total count |
PageRequest | Implementation | The usual way to create a Pageable |
Page<T> runs an additional count query to learn the total number of rows. If you only need "is there a next page" (infinite scroll), return Slice<T> instead and skip the count.
Use the static factory methods on PageRequest.
Page numbers start at 0. A page size of 10 and page number 2 returns rows 21 to 30. Use Pageable.unpaged() when a method accepts a Pageable but you want all rows.
Declare a Pageable parameter and return Page<T>. Spring Data generates the query and the count query.
JpaRepository already inherits findAll(Pageable) from PagingAndSortingRepository. Since Spring Data 3, that interface no longer extends CrudRepository, but JpaRepository combines both, so you rarely notice.
Example output for 23 matching rows:
page.map(...) transforms the content while keeping the metadata, which is how you convert entities to DTOs.
Spring Data's web support resolves a Pageable from the query string (?page=0&size=10&sort=name,asc) when you declare it as a controller parameter. With Spring Boot this is auto-configured.
Limit the maximum page size with spring.data.web.pageable.max-page-size (the default is 2000), so a client cannot request an entire table. Since Spring Data 3.3, returning a Page directly from a controller logs a warning about an unstable JSON structure; either wrap it in PagedModel (new PagedModel<>(page)) or enable @EnableSpringDataWebSupport(pageSerializationMode = PageSerializationMode.VIA_DTO).
ScrollPosition and Window<T> in Spring Data 3.1 and later.Slice<T> when you do not need the total count; it saves the extra count(*) query.Yes. PageRequest.of(0, 10) is the first page. Request parameters ?page=0 follow the same convention unless you set spring.data.web.pageable.one-indexed-parameters=true.
Page knows the total number of elements and pages, so it runs a count query. Slice only knows whether another slice exists and is cheaper.
Pass several Sort.Order values to Sort.by(...), or send ?sort=name,asc&sort=createdAt,desc in the request.
Yes, but wrap it in PagedModel or use the DTO serialization mode, because the default PageImpl JSON shape is not guaranteed to stay stable.
Pageable describes which page you want and how it is sorted; Page<T> returns that page with its total counts. Create requests with PageRequest.of, accept Pageable in repository methods and controllers, use Slice when you do not need totals, and switch to keyset scrolling for very large offsets.