diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java index 71dfc6a80da..38be5c4b501 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfiguration.java @@ -69,6 +69,10 @@ public class SpringDataWebAutoConfiguration { PageRequest.of(0, pageable.getDefaultPageSize())); resolver.setPageParameterName(pageable.getPageParameter()); resolver.setSizeParameterName(pageable.getSizeParameter()); + resolver.setPrefix(pageable.getPrefix()); + resolver.setQualifierDelimiter(pageable.getQualifierDelimiter()); + resolver.setMaxPageSize(pageable.getMaxPageSize()); + resolver.setOneIndexedParameters(pageable.isOneIndexedParameters()); }; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebProperties.java index b56b03058d7..95e9961e1d3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebProperties.java @@ -59,6 +59,28 @@ public class SpringDataWebProperties { */ private int defaultPageSize = 20; + /** + * Configures a general prefix to be prepended to the page number and page size parameters. + */ + private String prefix; + + /** + * Configures the delimiter to be used between the qualifier and the actual page number and size properties. + */ + private String qualifierDelimiter; + + /** + * Configures the maximum page size to be accepted. + */ + private int maxPageSize = 2000; + + /** + * Whether to expose and assume 1-based page number indexes in the request parameters. + * Defaults to {@literal false}, meaning a page number of 0 in the request equals the first page. + * If this is set to {@literal true}, a page number of 1 in the request will be considered the first page. + */ + private boolean oneIndexedParameters = false; + public String getPageParameter() { return this.pageParameter; } @@ -82,6 +104,38 @@ public class SpringDataWebProperties { public void setDefaultPageSize(int defaultPageSize) { this.defaultPageSize = defaultPageSize; } + + public String getPrefix() { + return prefix; + } + + public void setPrefix(final String prefix) { + this.prefix = prefix; + } + + public String getQualifierDelimiter() { + return qualifierDelimiter; + } + + public void setQualifierDelimiter(final String qualifierDelimiter) { + this.qualifierDelimiter = qualifierDelimiter; + } + + public int getMaxPageSize() { + return maxPageSize; + } + + public void setMaxPageSize(final int maxPageSize) { + this.maxPageSize = maxPageSize; + } + + public boolean isOneIndexedParameters() { + return this.oneIndexedParameters; + } + + public void setOneIndexedParameters(final boolean oneIndexedParameters) { + this.oneIndexedParameters = oneIndexedParameters; + } } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java index 2abc906fe8a..64f22b10fa4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/web/SpringDataWebAutoConfigurationTests.java @@ -78,7 +78,11 @@ public class SpringDataWebAutoConfigurationTests { public void customizePageable() { load("spring.data.web.pageable.page-parameter=p", "spring.data.web.pageable.size-parameter=s", - "spring.data.web.pageable.default-page-size=10"); + "spring.data.web.pageable.default-page-size=10", + "spring.data.web.pageable.prefix=abc", + "spring.data.web.pageable.qualifier-delimiter=__", + "spring.data.web.pageable.max-page-size=100", + "spring.data.web.pageable.one-indexed-parameters=true"); PageableHandlerMethodArgumentResolver argumentResolver = this.context .getBean(PageableHandlerMethodArgumentResolver.class); assertThat(ReflectionTestUtils.getField(argumentResolver, "pageParameterName")) @@ -87,6 +91,14 @@ public class SpringDataWebAutoConfigurationTests { .isEqualTo("s"); assertThat(ReflectionTestUtils.getField(argumentResolver, "fallbackPageable")) .isEqualTo(PageRequest.of(0, 10)); + assertThat(ReflectionTestUtils.getField(argumentResolver, "prefix")) + .isEqualTo("abc"); + assertThat(ReflectionTestUtils.getField(argumentResolver, "qualifierDelimiter")) + .isEqualTo("__"); + assertThat(ReflectionTestUtils.getField(argumentResolver, "maxPageSize")) + .isEqualTo(100); + assertThat(ReflectionTestUtils.getField(argumentResolver, "oneIndexedParameters")) + .isEqualTo(true); } @Test diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 529ea993c0c..142550af787 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -646,7 +646,11 @@ content into your application. Rather, pick only the properties that you need. # DATA WEB ({sc-spring-boot-autoconfigure}/data/web/SpringDataWebProperties.{sc-ext}[SpringDataWebProperties]) spring.data.web.pageable.default-page-size=20 # Default page size. + spring.data.web.pageable.max-page-size=2000 # Configures the maximum page size to be accepted. + spring.data.web.pageable.one-indexed-parameters=false # Whether to expose and assume 1-based page number indexes in the request parameters. spring.data.web.pageable.page-parameter=page # Page index parameter name. + spring.data.web.pageable.prefix= # Configures a general prefix to be prepended to the page number and page size parameters. + spring.data.web.pageable.qualifier-delimiter= # Configures the delimiter to be used between the qualifier and the actual page number and size properties. spring.data.web.pageable.size-parameter=size # Page size parameter name. spring.data.web.sort.sort-parameter=sort # Sort parameter name.