spring-projects / spring-data-rest

Simplifies building hypermedia-driven REST web services on top of Spring Data repositories
https://spring.io/projects/spring-data-rest
Apache License 2.0
920 stars 563 forks source link

Provide a property for the minimum page number [DATAREST-952] #1322

Open spring-projects-issues opened 7 years ago

spring-projects-issues commented 7 years ago

Abhijit Sarkar opened DATAREST-952 and commented

Spring Data REST paging starts the page number from zero and I've not found a way to change that. This is problematic for projects where paging exists without Spring Data (the API becomes inconsistent), or for business requirements that page number must start from 1. It'll be nice to have a property to determine the minimum page number that defaults to zero (so that existing users are not made unhappy). If the user provides a page number below the minimum page number configured, HTTP 400 should be returned


Affects: 2.5.5 (Hopper SR5)

spring-projects-issues commented 7 years ago

Oliver Drotbohm commented

You can extend RepositoryRestMvcConfiguration and override the bean definition for pageableResolver()

spring-projects-issues commented 7 years ago

Abhijit Sarkar commented

Ok, but I think from the following code, it's clear that the start page number is the only non-configurable property. I'm not saying that there's no workaround, but it's certainly can be easier.

@Bean
@Override
public HateoasPageableHandlerMethodArgumentResolver pageableResolver() {

    HateoasPageableHandlerMethodArgumentResolver resolver = super.pageableResolver();
    resolver.setPageParameterName(config().getPageParamName());
    resolver.setSizeParameterName(config().getLimitParamName());
    resolver.setFallbackPageable(new PageRequest(0, config().getDefaultPageSize()));
    resolver.setMaxPageSize(config().getMaxPageSize());

    return resolver;
}