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

佐手、 提交于 2020-01-11 07:51:53

问题


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. Please guide. 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:


回答1:


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



来源:https://stackoverflow.com/questions/56786158/unable-to-override-defaults-of-pagination-in-spring-boot-2-1-6-release

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!