My REST contorller:
@GetMapping("/test") public Page<MyObject> pathParamTest(Pageable pageable) { return myService.getPage(pageable); }
I send a request like following:
localhost:8091/endpoint/test?page=0&size=3&sort=id&direction=DESC
It's my response from server:
{ "content": [ { "id": 1 }, { "id": 2 }, { "id": 3 } ], "last": true, "totalPages": 1, "totalElements": 3, "first": true, "sort": [ { "direction": "ASC", "property": "id", "ignoreCase": false, "nullHandling": "NATIVE", "descending": false, "ascending": true } ], "numberOfElements": 3, "size": 3, "number": 0 }
but the request has still direction = ASC.
How can I send to server direction = DESC?
And why response has a field "last" = true, because next page has one element more?
Spring Data REST PaginationThe results will be returned based on the page number, page size, and sorting direction. Spring Data REST automatically recognizes URL parameters like page, size, sort etc. By default, the page size is 20, but we can change it by calling something like http://localhost:8080/subjects?page=10.
Spring Boot Pagination Example entity class of the application. annotation specifies that the class is a JPA entity and is mapped to a database table. sets the strategy that the database should use to generate the primary keys.
Adjective. pageable (not comparable) That can be paged. (computer science, of computer memory) That accepts paging.
PageRequest. first() Returns the Pageable requesting the first page. Sort. getSort()
try localhost:8091/endpoint/test?page=0&size=3&sort=id,DESC
from spring data rest 6.2. Sorting
curl -v "http://localhost:8080/people/search/nameStartsWith?name=K&sort=name,desc"
sort Properties that should be sorted by in the format property,property(,ASC|DESC). Default sort direction is ascending. Use multiple sort parameters if you want to switch directions, e.g. ?sort=firstname&sort=lastname,asc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With