The Pageable interface in Spring Data is an abstraction that carries a page request: the zero-based page index, the page size and the sort order. You pass it to a repository method, and Spring Data translates it into a database query that returns only one slice of the data, so you never load a whole table into memory.
It is the single parameter that makes pagination and sorting uniform across JPA, MongoDB, JDBC and other Spring Data modules, and it can be bound automatically from HTTP request parameters in Spring MVC.
org.springframework.data.domain.Pageable exposes these core members:
| Method | Purpose |
|---|---|
getPageNumber() | Zero-based index of the requested page |
getPageSize() | Maximum number of items per page |
getOffset() | Calculated as page number times page size |
getSort() | The Sort to apply |
next(), previousOrFirst(), first() | Navigate to related page requests |
isPaged() / unpaged() | Whether paging applies, or a constant that disables it |
The usual implementation is PageRequest. You create it with a static factory and hand it to a repository.
Any repository that extends PagingAndSortingRepository or JpaRepository has findAll(Pageable). Derived queries and @Query methods accept a Pageable as their last parameter too.
For a Page return type, Spring Data runs the data query with LIMIT and OFFSET (or the database's equivalent) and a second count query. Returning Slice<Customer> skips the count query and only tells you whether a next slice exists, which is cheaper for infinite scroll. Returning List<Customer> also works when you need neither.
In Spring MVC, declare Pageable as a controller argument. Spring Data's PageableHandlerMethodArgumentResolver builds it from the page, size and sort parameters.
A request such as /customers?page=0&size=10&sort=lastName,asc&sort=age,desc produces a Pageable with two sort orders. Spring Boot registers this resolver automatically. Use the properties spring.data.web.pageable.default-page-size and spring.data.web.pageable.max-page-size to set defaults and a safety cap.
| Type | Role |
|---|---|
Pageable | Input: which page you want and how to sort it |
Page<T> | Output: content plus total elements and total pages (extra count query) |
Slice<T> | Output: content plus whether a next slice exists (no count query) |
Sort | Sorting only, without paging |
ScrollPosition and Window, available in Spring Data since 3.1.PropertyReferenceException and a client can sort by an unindexed column.PageImpl directly in new code. Since Spring Data 3.3 a stable DTO shape is available through PagedModel or @EnableSpringDataWebSupport(pageSerializationMode = ...VIA_DTO).It is zero-based: page 0 is the first page. Spring Data web support can interpret request parameters as one-based with spring.data.web.pageable.one-indexed-parameters=true, but the Pageable itself stays zero-based.
Pageable is the interface, and PageRequest is its standard immutable implementation created with PageRequest.of(...). In controllers you normally accept Pageable and let Spring build the PageRequest.
Pass Pageable.unpaged(). Repositories then return all results, wrapped in a Page if the method requires it.
A Page return type needs the total count, so Spring Data issues a count query in addition to the data query. Use Slice to avoid it.
Pageable describes which page you want, how large it is and how it is sorted, and Spring Data turns it into an efficient database query. Use PageRequest.of in code, accept Pageable in controllers, choose Page or Slice for the result, and cap page sizes and sort properties on public APIs.