spring.data.rest.max-page-size 似乎不起作用 [英] spring.data.rest.max-page-size does not seem to be working

查看:28
本文介绍了spring.data.rest.max-page-size 似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Under Spring Boot 1.3.0.M5 I'm using

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

application.properties中.

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

But I still can set the size to 40 in a URL and get a correct response. For example : http://localhost:8080/cine20-spring/api/films?page=0&size=40&sort=title,asc

会给我回 40 部电影

will give me back 40 films

那么这个参数有什么用呢?

So what is the use of this parameter ?

使用 Spring-Boot 1.4.2 更新测试

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

There is still a problem : By default WITHOUT the dependencies spring-boot-starter-data-rest , the max-page-size is set to 2000 by default and changing the max-page-size value won't work :

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

添加spring-boot-starter-data-rest=>最大页面大小现在默认设置为 1000,然后更改参数 max-page-size 将起作用:

Adding spring-boot-starter-data-rest => the max-page-size is now set to 1000 by default , then changing the param max-page-size will work:

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

我仍然相信,这是一种奇怪的行为.

I still believe, this is strange behavior.

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

You could find private int maxPageSize = 1000; which explains why it changed to 1000. I haven't found, why it is set to 2000 from the start though.

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

I would like to set the param spring.data.rest.max-page-size freely without the need to add the dependency : spring-boot-starter-data-rest, but unfortunately I haven't found a way so far.

推荐答案

这对我来说有点问题.我认为最简单的解决方案是使用配置属性而不是代码.所以这就是我发现的并且对我有用.

This was somewhat of a gotcha for me. I think the easiest solution is using configuration properties instead of code. So this is what I found and what worked for me.

如果您在 @RestController 中使用 Pageable 那么您可以使用属性 spring.data.web.pageable.max-page-size 设置它.

If you are using a Pageable in a @RestController then you can set it using property spring.data.web.pageable.max-page-size.

如果您在 @RepositoryRestResource 中使用 Pageable 那么您可以使用属性 spring.data.rest.max-page-size.

If you are using a Pageable in a @RepositoryRestResource then you can set it using property spring.data.rest.max-page-size.

这篇关于spring.data.rest.max-page-size 似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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