无法覆盖Spring Boot 2.1.6.RELEASE中的分页默认值? [英] Unable to override defaults of Pagination in Spring Boot 2.1.6.RELEASE?

查看:119
本文介绍了无法覆盖Spring Boot 2.1.6.RELEASE中的分页默认值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Spring Boot Spring Data Mongo Pageable示例.如果没有人提供任何值,我想将分页值设置为默认值page=1size=5.

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.

现在,当用户提供任何值时,我希望Pageable对象使用这些值而不是默认值.

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

已修复的Bug: https://jira.spring.io/browse/DATAMONGO-2313

在我的情况下不起作用.我在我的应用程序中使用Spring HATEOAS.

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);
}

application.yml文件中

# 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

或者我想像下面那样使用Spring Boot

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用户界面:

Swagger UI:

推荐答案

我看到的报告是application.yml中的pageable设置仅适用于Spring HATEOAS.我会尝试使用@PageableDefault注释代替.

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

这篇关于无法覆盖Spring Boot 2.1.6.RELEASE中的分页默认值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆