Spring Data binds page, size and sort straight from the query string.
@GetMapping("/orders")
Page<Order> list(@PageableDefault(size = 20, sort = "placedAt",
direction = Sort.Direction.DESC) Pageable pageable) {
return repo.findAll(pageable);
}
GET /orders?page=2&size=50&sort=total,desc
{"content":[...],"totalElements":431,"totalPages":9,"number":2}
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11