Skip to content
Ameen Abozaid
Planned lessonJNR-019-L05

Pagination

  • Lesson 5 of 8
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

return lists in pages.

Planned topics

  • An unbounded list grows until it breaks the server and the client.
  • Use page (starting at 0 or 1; pick one) and size query parameters.
  • Cap the size: if the client asks for 10,000, return at most your maximum (for example 100).
  • Return the page items plus metadata: page, size, total elements, total pages.
  • Spring Data offers Pageable; with the in-memory repository now, implement it by hand and swap later (JNR-P4).
Draft outline details

Demonstration

java
int safeSize = Math.min(Math.max(size, 1), 100);
List<Product> slice = all.stream().skip((long) page * safeSize).limit(safeSize).toList();

Check your understanding

Why cap size?

Show answer

One request must not be able to load everything.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.