spring.data.rest.max-page-size似乎不起作用?

时间:2015-11-12 15:40:04

标签: spring-data-rest

在Boot 1.3.0.M5下我使用 在application.properties

spring.data.rest.max-page-size=10

但是我仍然可以在URL中将大小设置为40并获得正确的响应。 例如 : http://localhost:8080/cine20-spring/api/films?page=0&size=40&sort=title,asc

会给我40部电影

那么这个参数的用途是什么?

使用Spring-Boot 1.4.2更新测试

还有一个问题: 默认情况下没有依赖项 spring-boot-starter-data-rest ,默认情况下,max-page-size设置为 2000 并且更改max-page-size值将不起作用:

spring.data.rest.max-page-size=0x7fffffff

不起作用。

添加 spring-boot-starter-data-rest =>默认情况下,max-page-size现在设置为 1000 ,然后更改param max-page-size将起作用:

spring.data.rest.max-page-size=0x7fffffff

会奏效。

我仍然认为这是一种奇怪的行为。

in:https://github.com/spring-projects/spring-data-rest/blob/master/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/RepositoryRestConfiguration.java

你可以找到private int maxPageSize = 1000;这解释了为什么它改为1000.我没有找到为什么它从一开始就设置为2000 ......

我想自由设置param spring.data.rest.max-page-size而无需添加依赖项: spring-boot-starter-data-rest ,但是 到目前为止,我还没有找到办法。

5 个答案:

答案 0 :(得分:2)

这对我来说有点陷阱。我认为最简单的解决方案是使用配置属性而不是代码。所以这就是我发现的东西,对我有用。

如果您在Pageable中使用@RestController,则可以使用属性spring.data.web.pageable.max-page-size进行设置。

如果您在Pageable中使用@RepositoryRestResource,则可以使用属性spring.data.rest.max-page-size进行设置。

答案 1 :(得分:1)

我刚试过 - 我认为你的期望是正确的 - 它设定了一个页面的最大限制。

但我认为你的房产名称不正确 - 试试这个:

spring.data.rest.maxPageSize=10

请参阅此处获取文档: http://docs.spring.io/spring-data/rest/docs/2.4.0.RELEASE/reference/html/#_changing_other_spring_data_rest_properties

答案 2 :(得分:1)

我能够在Spring Boot 2.1.x和2.3.3上做到这一点,以覆盖默认的Pageable最大页面大小2000。

@Configuration
public class PageableConfig {

    @Bean
    PageableHandlerMethodArgumentResolverCustomizer pageableResolverCustomizer() {
        return pageableResolver -> pageableResolver.setMaxPageSize(9999);
    }

}

spring.data.web.pageable.max-page-sizespring.data.web.pageable.maxPageSize)或spring.data.rest.max-page-sizespring.data.rest.maxPageSize)属性(添加到application.properties)对我不起作用。即

# these properties did not allow me to override the default of 2000 for maxPageSize
spring.data.web.pageable.max-page-size=9999
spring.data.rest.max-page-size=9999

有关详细信息,请参见https://github.com/spring-projects/spring-boot/issues/14413https://jira.spring.io/browse/DATAREST-1290

请参阅相关的SO:为JPA Pageable Object post设置默认页面大小: Set default page size for JPA Pageable Object

答案 3 :(得分:0)

仅通过代码执行配置为我工作:

@Configuration
public class CustomizedRestMvcConfiguration extends RepositoryRestMvcConfiguration
{
  @Override
  public RepositoryRestConfiguration config() {
    RepositoryRestConfiguration config = super.config();
    config.setMaxPageSize(10000);
    return config;
  }
}

http://docs.spring.io/spring-data/rest/docs/2.4.0.RELEASE/reference/html/#_changing_the_base_uri

答案 4 :(得分:0)

尝试一下将起作用 在属性中添加此行

spring.data.rest.default-page-size=1000
相关问题