@PageableDefault sets the default page number, page size and sort order that Spring Data's web support applies to a Pageable controller parameter when the client sends no page, size or sort request parameters. It lives in org.springframework.data.web and only affects controller method arguments, not repository methods called from your own code.
Without it, Spring MVC falls back to a global default of page 0 and size 20 with no sorting. With it, each endpoint can declare its own defaults while clients can still override them in the query string.
When Spring Data web support is active (Spring Boot enables it automatically when Spring Data is on the classpath), a PageableHandlerMethodArgumentResolver converts the request parameters page, size and sort into a Pageable. If a parameter is missing, the resolver uses the values from @PageableDefault, or the global fallback when the annotation is absent.
The annotation has these attributes:
| Attribute | Meaning | Default |
|---|---|---|
value / size | Page size | 10 |
page | Zero-based page index | 0 |
sort | Property names to sort by | none |
direction | Sort.Direction.ASC or DESC, applied to every property in sort | ASC |
Note that the annotation default for size is 10, while the global fallback used when the annotation is absent is 20. That difference surprises many developers.
A request to /products returns the first 25 products sorted by name. A request to /products?page=2&size=50&sort=price,desc overrides every default, so the client always has the last word.
@PageableDefault applies a single direction to all sort properties. When you need different directions, combine it with @SortDefault.SortDefaults:
Here @PageableDefault controls page and size, and @SortDefault controls the default ordering. Sorting on properties that do not exist on the entity raises a PropertyReferenceException, so consider whitelisting sortable fields for public APIs.
To change defaults for every endpoint, use configuration properties rather than repeating the annotation:
max-page-size is important for security and stability: without a cap, a client can request size=1000000 and load a huge result set. Spring Data caps requested sizes at 2000 by default, and you should lower it to match your API.
An annotation on a method overrides the global default for that endpoint. Prefer the global properties for the common case and @PageableDefault for exceptions.
Pageable does not apply any default.one-indexed-parameters=true, page=1 is the first page, but the page attribute of the annotation remains zero-based in the resulting Pageable.max-page-size are reduced to the maximum.Page entities directly from controllers. Since Spring Data 3.3 serializing PageImpl as-is logs a warning because its JSON shape is not guaranteed stable. Use @EnableSpringDataWebSupport(pageSerializationMode = EnableSpringDataWebSupport.PageSerializationMode.VIA_DTO) or return your own DTO or PagedModel.The Spring Data web support falls back to page 0 with a size of 20 and no sorting. You can change the size with spring.data.web.pageable.default-page-size.
Yes. The annotation only supplies defaults. Any page, size or sort request parameter the client sends takes precedence.
No. It is processed only for controller handler method parameters. Repository methods receive whatever Pageable you pass them.
Use @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC). For mixed directions use @SortDefault.SortDefaults.
@PageableDefault gives each controller endpoint sensible default page, size and sort values while letting clients override them through query parameters. Combine it with @SortDefault for mixed sort directions, and use spring.data.web.pageable.* properties for global defaults and a maximum page size. Remember that it applies only to MVC handler arguments.