spring-projects / spring-projects/spring-data-commons

Pagination from page 1 (one-indexed-parameters) not runs well

Open
#2,889 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: feedback-provided
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.