spring-data-rest
spring-data-rest copied to clipboard
springboot pageable.one-indexed-parameters=true response pageNumber -1 [DATAREST-1454]
Say.li opened DATAREST-1454 and commented
application.yml spring: data: web: pageable:
one-indexed-parameters: true
requset: Pageable page 1
response: page.getNumber() page.getPageable().getPageNumber() 0
Expect: 1
Affects: 3.2.1 (Moore SR1)
1 votes, 2 watchers
Oliver Drotbohm commented
Can please add more information about the request you send, how many items are returned etc. "Pageable page 1" is not a description of a request we can work with
Say.li commented
one-indexed-parameters: true
request: http request parameter:
page=1
spring java object Pageable
page=0
response:
http response parameter:
number=0
spring java object page
number=0
Unhandled response value
@RestController
Oliver Drotbohm commented
That's not any more detailed than the original request. Ideally, I'd love to see a sample project and a test case that fails. Or at least some documented web requests (e.g. via curl) and the resulting output and in how far that differs from what's expected
Say.li commented
@GetMapping
public Page<ExpertEntity> page(String name, String typeId, String createUserId, Date createStartDate, Date createEndDate, Boolean deleted, @SortDefault.SortDefaults({
@SortDefault(sort = "deleted", direction = Sort.Direction.ASC),
@SortDefault(sort = "sort", direction = Sort.Direction.DESC),
@SortDefault(sort = "createDate", direction = Sort.Direction.DESC)
}) Pageable pageable) {
return this.expertService.page(name, typeId, createUserId, createStartDate, createEndDate, deleted, pageable);
}
spring:
data:
web:
pageable:
one-indexed-parameters: true
curl -X GET \
'http://localhost:8082/managerUser?sort=createDate,deleted&page=1' \
-H 'Accept: */*' \
-H 'Accept-Encoding: gzip, deflate' \
-H 'Cache-Control: no-cache' \
-H 'Connection: keep-alive' \
-H 'Cookie: SESSION=OGU3YmFjNWItNzYyNy00MjBlLWE3ODMtY2ZhYmE5NWEzN2M5' \
-H 'Host: localhost:8082' \
-H 'Postman-Token: 265bd69e-5ddb-4168-bbad-cdc05ba5b9b7,262e299f-d46f-4338-9e12-a80d5a6c16f9' \
-H 'User-Agent: PostmanRuntime/7.20.1' \
-H 'cache-control: no-cache'
response
{
"content": [
{
"deleted": false,
"updateDate": "2019-11-15 15:41:28",
"createDate": "2019-09-09 16:41:31",
"id": "1d4b8fb5-b3f0-4122-a444-c1eceb5526fa",
"username": "15828395524",
"name": "李飞龙",
"department": "云服务部",
"enabled": true,
"authoritys": [
{
"deleted": false,
"updateDate": "2019-09-10 16:06:33",
"createDate": "2019-09-10 16:06:33",
"id": "a82c7a21-843d-4fc0-9838-fe953a484855",
"name": "管理员管理",
"uriResources": [
{
"name": "管理员管理",
"uri": "/managerUser/**",
"method": null
}
]
}
]
},
{
"deleted": false,
"updateDate": "2019-09-11 13:46:31",
"createDate": "2019-09-11 13:46:31",
"id": "37360cbd-86c5-4a44-9440-8a0203dd1c64",
"username": "15202805172",
"name": "杨鹏",
"department": null,
"enabled": true,
"authoritys": [
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "60d37d03-02cb-4f71-a9ae-4cb7f460a90d",
"name": "社区管理",
"uriResources": [
{
"name": "社区管理",
"uri": "/post/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "7951c0f5-372c-40f1-978c-fb7e1f360870",
"name": "开发者管理",
"uriResources": [
{
"name": "开发者管理",
"uri": "/developer/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "a2af4588-db41-4782-8f0e-b4a6f3ff5f3e",
"name": "内容管理",
"uriResources": [
{
"name": "内容管理",
"uri": "/content/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-10 16:06:33",
"createDate": "2019-09-10 16:06:33",
"id": "a82c7a21-843d-4fc0-9838-fe953a484855",
"name": "管理员管理",
"uriResources": [
{
"name": "管理员管理",
"uri": "/managerUser/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "bffa63c8-705b-4ee9-8e8b-a32aec56b44a",
"name": "应用管理",
"uriResources": [
{
"name": "应用管理",
"uri": "/application/**",
"method": null
}
]
}
]
},
{
"deleted": false,
"updateDate": "2019-11-01 09:56:59",
"createDate": "2019-11-01 09:56:59",
"id": "ebd88126-c7c3-4414-b267-efcd145dc0ad",
"username": "15681155356",
"name": "何娟",
"department": null,
"enabled": true,
"authoritys": [
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "60d37d03-02cb-4f71-a9ae-4cb7f460a90d",
"name": "社区管理",
"uriResources": [
{
"name": "社区管理",
"uri": "/post/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "7951c0f5-372c-40f1-978c-fb7e1f360870",
"name": "开发者管理",
"uriResources": [
{
"name": "开发者管理",
"uri": "/developer/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "a2af4588-db41-4782-8f0e-b4a6f3ff5f3e",
"name": "内容管理",
"uriResources": [
{
"name": "内容管理",
"uri": "/content/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-10 16:06:33",
"createDate": "2019-09-10 16:06:33",
"id": "a82c7a21-843d-4fc0-9838-fe953a484855",
"name": "管理员管理",
"uriResources": [
{
"name": "管理员管理",
"uri": "/managerUser/**",
"method": null
}
]
},
{
"deleted": false,
"updateDate": "2019-09-09 16:15:46",
"createDate": "2019-09-09 16:15:46",
"id": "bffa63c8-705b-4ee9-8e8b-a32aec56b44a",
"name": "应用管理",
"uriResources": [
{
"name": "应用管理",
"uri": "/application/**",
"method": null
}
]
}
]
}
],
"pageable": {
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"offset": 0,
"pageNumber": 0,
"pageSize": 10,
"paged": true,
"unpaged": false
},
"totalElements": 3,
"totalPages": 1,
"last": true,
"size": 10,
"sort": {
"sorted": true,
"unsorted": false,
"empty": false
},
"number": 0,
"numberOfElements": 3,
"first": true,
"empty": false
}
debugger Pageable page equals 0, http param page equals 1
response pageNumber and number equals 0, Unaffected one-indexed-parameters
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
I had the same issue, but found that it's based on misunderstanding what the spring.data.web.pageable.one-indexed-parameters
property does. It does not make the Pageable
one-indexed, only the request parameter. This Stack Overflow answer provides a good code sample and explanation.
I think this issue can either be closed, or, seeing how the property has proven confusing, fixed by expanding the documentation or renaming it. It's probably not worth the hassle of creating a new property and deprecating the current one, but something like spring.data.web.pageable.binding.one-indexed-parameters
could make clear that it doesn't affect the Pageable
itself. A simpler solution would be to add a sentence to the javadoc to clarify that, if set to true
, the page number n
in the request will correspond to n - 1
in the Pageable
.