First attempts at pagination

Report a typo

You have a table in a database based on the following class (the table's name and fields are the same):

Java
@Entity
public class Product {
    
    @Id
    @GeneratedValue
    private long id;
    private String model;
    private String type;
    private int price;

    // constructor, getters, setters
}
Kotlin
@Entity
data class Product(
    @Id
    @GeneratedValue
    val id: Long = 0,
    val model: String = "",
    val type: String = "",
    val price: Int = 0
)

You want to sort your data by the price in ascending order and then page it. Which lines of code do you need to do it and get the data for the second page? The page size is 10. Your repository's name is repository and it extends PagingAndSortingRepository.

Java
  1. Page<Product> productPage = repository.findAll(PageRequest.of(1, 10, Sort.by("price")));
  2. Page<Product> productPage = repository.findAll(PageRequest.of(2, 10, Sort.Direction.ASC, "price"));
  3. Page<Product> productPage = repository.findAll(PageRequest.of(2, 10, "price"));
  4. Page<Product> productPage = repository.findAll(PageRequest.of(1, 10, "price"));
  5. Page<Product> productPage = repository.findAll(PageRequest.of(1, 10, Sort.Direction.ASC, "price"));
Kotlin
  1. val productPage: Page<Product> = repository.findAll(PageRequest.of(1, 10, Sort.by("price")))
  2. val productPage: Page<Product> = repository.findAll(PageRequest.of(2, 10, Sort.Direction.ASC, "price"))
  3. val productPage: Page<Product> = repository.findAll(PageRequest.of(2, 10, Sort.by("price")))
  4. val productPage: Page<Product> = repository.findAll(PageRequest.of(1, 10, Sort.by("price")))
  5. val productPage: Page<Product> = repository.findAll(PageRequest.of(1, 10, Sort.Direction.ASC, "price"))
Select one or more options from the list
___

Create a free account to access the full topic