Spring 分页 - 请求参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44757218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 01:26:44  来源:igfitidea点击:

Spring pagination - request parameters

springrestspring-mvc

提问by user

My REST contorller:

我的 REST 控制器:

    @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.

但请求仍然有方向 = ASC。

How can I send to server direction = DESC?

如何发送到服务器方向 = DESC?

And why response has a field "last" = true, because next page has one element more?

为什么响应有一个字段“last”= true,因为下一页还有一个元素?

回答by xyz

try localhost:8091/endpoint/test?page=0&size=3&sort=id,DESC

尝试 localhost:8091/endpoint/test?page=0&size=3&sort=id,DESC

from spring data rest 6.2. Sorting

春季数据休息 6.2。排序

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.

curl -v " http://localhost:8080/people/search/nameStartsWith?name=K&sort=name,desc"

sort 应按格式 property,property(,ASC|DESC) 排序的属性。默认排序方向是升序。如果要切换方向,请使用多个排序参数,例如 ?sort=firstname&sort=lastname,asc。