Skip to content
Ameen Abozaid
Planned lessonJNR-029-L05

Projections and paging

  • Lesson 5 of 7
  • 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 only the columns a screen needs, one page at a time.

Planned topics

  • A projection is a read-only view: an interface with getters or a record.
  • It selects only the needed columns, no entity tracking.
  • Pageable carries page number, size, and sort; PageRequest.of(0, 20, Sort.by("name")).
  • Return Page<T> (with total count) or Slice<T> (no count query).
  • Map to a response DTO in the service; never return entities from controllers.
Draft outline details

Demonstration

java
public record ProductListItem(Long id, String name, BigDecimal priceAmount) {}

@Query("select new com.shop.ProductListItem(p.id, p.name, p.price.amount) from Product p")
Page<ProductListItem> list(Pageable pageable);

Check your understanding

What does Page have that Slice does not?

Show answer

The total count.

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.