Pagination is a technique to split large sets of data into smaller, manageable chunks (pages), improving performance and user experience—especially in APIs and UI tables.
🔧 Why Use Pagination?
- 🐢 Prevents performance issues with large data sets.
- ⚡ Improves API response time.
- 📱 Better UX in frontend (infinite scroll, paged tables, etc.).
🔢 Example: Pagination in Spring Boot (Using Spring Data JPA)
💡 Output JSON:
📦 Repository Interface
🧠 Key Terms
Term |
Meaning |
Page |
Full page of results with metadata |
Pageable |
Interface for pagination info |
PageRequest.of(p, s) |
Creates a Pageable for page p of size s
|
🚀 Frontend-Friendly Params
Param |
Use |
page=0 |
First page (0-based index) |
size=10 |
Number of items per page |
sort=name,desc |
Sort by name in descending order |
✅ Bonus: Custom Query with Pagination