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
-
Page<Product> productPage = repository.findAll(PageRequest.of(1, 10, Sort.by("price"))); -
Page<Product> productPage = repository.findAll(PageRequest.of(2, 10, Sort.Direction.ASC, "price")); -
Page<Product> productPage = repository.findAll(PageRequest.of(2, 10, "price")); -
Page<Product> productPage = repository.findAll(PageRequest.of(1, 10, "price")); -
Page<Product> productPage = repository.findAll(PageRequest.of(1, 10, Sort.Direction.ASC, "price"));
Kotlin
-
val productPage: Page<Product> = repository.findAll(PageRequest.of(1, 10, Sort.by("price"))) -
val productPage: Page<Product> = repository.findAll(PageRequest.of(2, 10, Sort.Direction.ASC, "price")) -
val productPage: Page<Product> = repository.findAll(PageRequest.of(2, 10, Sort.by("price"))) -
val productPage: Page<Product> = repository.findAll(PageRequest.of(1, 10, Sort.by("price"))) -
val productPage: Page<Product> = repository.findAll(PageRequest.of(1, 10, Sort.Direction.ASC, "price"))