Unable to override defaults of Pagination in Spring Boot 2.1.6.RELEASE?
Asked Answered
A

1

0

I am working on Spring Boot Spring Data Mongo Pageable example. I want to set pagination value default page=1 and size=5, if no one provided any values.

Now when user provided any values, I want Pageable object to use those values and not default one.

Crated Bug: https://jira.spring.io/browse/DATAMONGO-2313

Its not working in my case. I'm not using Spring HATEOAS in my application.

@GetMapping()
public ResponseEntity<Page<Student>> getAllstudents(Pageable pageable){
    return studentService.findAllstudents(pageable);
}

in application.yml file

# Mongo DB details
  data:
    mongodb:
      database: TEST
      host: localhost
      port: 27017

    web:
      pageable:
        default-page-size: 2
        size-parameter: 0
        one-indexed-parameters: true
        page-parameter: page

Or I want exactly like below using Spring boot

<mvc:argument-resolvers>
            <bean class="org.springframework.data.web.PageableHandlerMethodArgumentResolver" >
                <property name="oneIndexedParameters" value="true"></property>
                <property name="pageParameterName" value="page"></property>
                <property name="sizeParameterName" value="size"></property>
                <property name="fallbackPageable">
                    <bean class="org.springframework.data.domain.PageRequest">
                        <constructor-arg name="page" value="1" />
                        <constructor-arg name="size" value="${paging.default.pageSize}" />
                    </bean>
                </property>
            </bean>
        </mvc:argument-resolvers>

Swagger UI:

enter image description here

Ariew answered 27/6, 2019 at 7:34 Comment(0)
I
0

I'm seeing reports that those pageable settings in application.yml only work with Spring HATEOAS. I would try using the @PageableDefault annotation instead.

Itchy answered 27/6, 2019 at 15:44 Comment(1)
Can we configure this as global level ? I dont see its possibleAriew

© 2022 - 2024 — McMap. All rights reserved.