Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring pagination - request parameters

Tags:

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?

like image 365
user Avatar asked Jun 26 '17 10:06

user


People also ask

How does Spring pagination work?

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.

How pagination works internally in spring boot?

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.

What is Pageable?

Adjective. pageable (not comparable) That can be paged. (computer science, of computer memory) That accepts paging.

What is PageRequest in spring?

PageRequest. first() Returns the Pageable requesting the first page. Sort. getSort()


1 Answers

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.

like image 95
xyz Avatar answered Oct 16 '22 13:10

xyz