Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix defaultValue when using @PageableDefault together with one-indexed-parameters #2881

Merged
merged 2 commits into from
Feb 8, 2025

Conversation

pheyken
Copy link
Contributor

@pheyken pheyken commented Jan 31, 2025

Hi,

we noticed that the default value for the page was 0 when having a spring-boot application with spring.data.web.pageable.one-indexed-parameters=true as well as using a @PageableDefault on the controller.

The @PageableDefault annotation has 0 as the default value for the page (see here). This is the desired behavior (as far as I can tell) as spring normalizes the pageable before injecting it into the controller method. This is done in this method.

So, e.g., if the newly added test controller was to be called with the following query parameters

/test1?prefix_pages=1

the injected pageable in the controller would return 0 for getPageNumber()

@GetMapping("/test1")
public String getPatientList1(
    @PageableDefault(size = 100, sort = { "someField", "someoTHER" }, direction = Sort.Direction.DESC) 
    @ParameterObject 
    Pageable pageable
) {
        System.out.println(pageable.getPageNumber()) // prints 0
	return "bla";
}

Let me know if you prefer to have a separate TestApp for this, happy to adjust this.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
…d-parameters
@bnasslahsen
Copy link
Collaborator

@pheyken,

Thank you for your contribution to the project!

@bnasslahsen bnasslahsen merged commit fb70f36 into springdoc:main Feb 8, 2025
1 check passed
@pheyken pheyken deleted the one-indexed-pageable-default branch February 10, 2025 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants