Spring pagination - request parameters

怎甘沉沦 提交于 2020-07-17 01:34:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/44757218/spring-pagination-request-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!