在我使用的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,但不幸的是我到目前为止还没有找到方法。
我们如何通过.properties文件进行以下配置?
@RequestParam(value = "page", required = false, defaultValue="0") Integer page,
@RequestParam(value = "size", required = false,defaultValue="8") Integer size,
Run Code Online (Sandbox Code Playgroud)
如何在Spring MVC中通过.properties文件制作defaultValue="0"和defaultValue="8"配置?我们如何才能做到这一点 @PageableDefault(size = 8, page = 0)?