在我使用的Spring Boot 1.3.0.M5下
spring.data.rest.max-page-size=10
Run Code Online (Sandbox Code Playgroud)
在application.properties 中。
但是我仍然可以在 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
Run Code Online (Sandbox Code Playgroud)
添加spring-boot-starter-data-rest => max-page-size 现在默认设置为1000,然后更改参数 max-page-size 将起作用:
spring.data.rest.max-page-size=0x7fffffff
Run Code Online (Sandbox Code Playgroud)
我仍然相信,这是奇怪的行为。
在:https : //github.com/spring-projects/spring-data-rest/blob/master/spring-data-rest-core/src/main/java/org/springframework/data/rest/core/config/存储库RestConfiguration.java
你可以找到private int maxPageSize = 1000;
这解释了为什么它变成了 1000。我还没有找到,为什么它从一开始就设置为 2000。
我想spring.data.rest.max-page-size
自由设置参数而不需要添加依赖项:spring-boot-starter-data-rest,但不幸的是我到目前为止还没有找到方法。
Raf*_*iek 15
这对我来说有点棘手。我认为最简单的解决方案是使用配置属性而不是代码。所以这就是我发现的,对我有用的。
如果您Pageable
在 a中使用 a@RestController
那么您可以使用 property 设置它spring.data.web.pageable.max-page-size
。
如果您Pageable
在 a中使用 a@RepositoryRestResource
那么您可以使用 property 设置它spring.data.rest.max-page-size
。
仅适用于通过代码强制执行的配置:
@Configuration
public class CustomizedRestMvcConfiguration extends RepositoryRestMvcConfiguration
{
@Override
public RepositoryRestConfiguration config() {
RepositoryRestConfiguration config = super.config();
config.setMaxPageSize(10000);
return config;
}
}
Run Code Online (Sandbox Code Playgroud)
http://docs.spring.io/spring-data/rest/docs/2.4.0.RELEASE/reference/html/#_chang_the_base_uri
归档时间: |
|
查看次数: |
9488 次 |
最近记录: |