spring-projects / spring-projects/spring-data-commons
Pagination from page 1 (one-indexed-parameters) not runs well
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 838
- Forks
- 730
- PR merge metrics
- No merged PRs in 30d
Description
Good morning from spain.
My scope is Spring boot 3.1 I'm implemeting REST service and I have pagination for return large list of elements. For default Spring boot manage the page from 0 index. I have reading that is possible start pagination from page 1, using this senetence in application.yaml:
spring:
data:
web:
pageable:
one-indexed-parameters: true
With new settings, the page 0 and the page 1 is the same. It show the same result. The problem is that the param "number" on paginations settings always show one page less, that I access:
Examples:
To page 0
Request:
{{base_url}}/system/business/pagination?size=5&page=0
Response details:
"pagination": {
"totalPages": 4,
"totalElements": 17,
"size": 5,
"number": 0,
"numberOfElements": 5,
"empty": false,
"first": true,
"last": false,
"sorted": false
}
Note: I would prefer that it returns null.
To page 1
Request:
{{base_url}}/system/business/pagination?size=5&page=1
Response details:
"pagination": {
"totalPages": 4,
"totalElements": 17,
"size": 5,
"number": 0,
"numberOfElements": 5,
"empty": false,
"first": true,
"last": false,
"sorted": false
}
Note: Returns the same that page 0. See that number value is wrong. It would have to be 1.
To page 2
Request:
{{base_url}}/system/business/pagination?size=5&page=2
Response details:
"pagination": {
"totalPages": 4,
"totalElements": 17,
"size": 5,
"number": 1,
"numberOfElements": 5,
"empty": false,
"first": false,
"last": false,
"sorted": false
}
Note: Return the page 2, but number value is 1.
Thanks for your attention
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file or test is named. Reproduce the requests with spring.data.web.pageable.one-indexed-parameters enabled, then trace how the request page and returned pagination number are mapped; done means the page-one behavior and reported number are consistent and covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100