提问者:小点点

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


在Spring Boot 1.3.0下。我正在使用M5

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

application.properties。

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

会还给我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=

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

我仍然相信,这是奇怪的行为。

在: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

您可以找到privacy int maxPageSize=1000;这解释了为什么它改为1000。我还没有找到,为什么它从一开始就设置为2000。

我想自由设置参数spring.data.rest. max-page-size,而不需要添加依赖项:spring-boot-starter-data-rest,但不幸的是,到目前为止我还没有找到方法。


共3个答案

匿名用户

这对我来说有点困难。我认为最简单的解决方案是使用配置属性而不是代码。这就是我发现的并且对我有用的方法。

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

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

匿名用户

我能够在Spring Boot 2.1. x和2.3.3上执行此操作以覆盖默认的Pag可分页最大页面大小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/14413及https://jira.spring.io/browse/DATAREST-1290

查看相关SO:为JPA可分页对象设置默认页面大小文章:为JPA可分页对象设置默认页面大小

匿名用户

仅在通过代码强制执行的配置下为我工作:

@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