Recall & Review
beginner
What is the purpose of the
Pageable interface in Spring Boot?The
Pageable interface helps to request a specific page of data with a defined size and sorting order. It makes it easy to handle pagination and sorting in database queries.Click to reveal answer
beginner
How do you specify sorting when using
Pageable?You can specify sorting by using
PageRequest.of(page, size, Sort.by("fieldName").ascending()) or PageRequest.of(page, size, Sort.by("fieldName").descending()) to sort the results by a field in ascending or descending order.Click to reveal answer
intermediate
What does the
Page object returned by a repository method contain?The
Page object contains the list of items for the requested page, total number of pages, total number of elements, current page number, and page size. It helps to navigate through paged data easily.Click to reveal answer
beginner
How can you enable pagination and sorting in a Spring Data JPA repository method?
Add a
Pageable parameter to the repository method signature, for example: Page<Entity> findAll(Pageable pageable);. Spring Data will automatically apply pagination and sorting based on the Pageable argument.Click to reveal answer
advanced
What is the difference between
Pageable and Slice in Spring Data?Pageable returns a Page which contains total count information, while Slice only knows if there is a next slice available and does not fetch total count, which can improve performance when total count is not needed.Click to reveal answer
Which method creates a
Pageable object for page 2 with 10 items per page sorted by 'name' ascending?✗ Incorrect
Page numbers are zero-based, so page 2 means index 1. The correct call is PageRequest.of(1, 10, Sort.by("name").ascending()).
What does the
Page interface provide besides the list of items?✗ Incorrect
Page provides metadata like total pages, total elements, current page number, and page size along with the content.How do you add pagination support to a Spring Data JPA repository method?
✗ Incorrect
Adding a
Pageable parameter enables pagination and sorting automatically.Which of the following is true about
Slice compared to Page?✗ Incorrect
Slice only knows if there is a next slice and does not fetch total count, improving performance.What is the default sort direction if not specified in
Pageable?✗ Incorrect
If no
Sort is provided when creating the Pageable, no sorting is applied.Explain how to implement pagination and sorting in a Spring Boot REST API using
Pageable.Think about how to request a specific page and sort order, and how to return the data with helpful info.
You got /4 concepts.
Describe the difference between
Page and Slice in Spring Data pagination.Focus on what metadata each provides and when you might prefer one over the other.
You got /4 concepts.