3

i tried many ways to edit default pagination value in spring boot to start with index 1 not zero

My app contain spring-security-oauth2 , spring-data dependencies

1 - This Way Not worked

@Configuration                                                                       
public class WebConfig extends WebMvcConfigurerAdapter {


    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        PageableHandlerMethodArgumentResolver resolver = new PageableHandlerMethodArgumentResolver();
        resolver.setOneIndexedParameters(true);
        resolver.setFallbackPageable(new PageRequest(1, 20));
        argumentResolvers.add(resolver);
        super.addArgumentResolvers(argumentResolvers);
    }
}

2- adding this property in application.yml not working

spring.data.web.pageable.one-indexed-parameters=true

i just need to start pagination from page=1

like this URL http://localhost:8080/api/v1/articles/page?page=1 [should return first page]

NOT THAT http://localhost:8080/api/v1/articles/page?page=0 [should return empty content]

Guillaume S
  • 1,462
  • 2
  • 19
  • 31
Salah Atwa
  • 1,648
  • 2
  • 12
  • 13
  • 1
    Are you sure that you are on the right way? Here is an in theory working [example](http://www.bswen.com/2018/06/springboot-springboot-2-with-JPA-pagination-example.html) without PageableHandlerMethodArgumentResolver – m4gic Aug 30 '18 at 12:03
  • i need to custom default value for page param , i need to start pagination with 1 not zero – Salah Atwa Aug 30 '18 at 12:07
  • I would stick to the example I have sent to you and I would manipulate the request (either manipulating the parsed Pageable object or (if it is not possible) or [manipulating the request](https://nofluffjuststuff.com/blog/lincoln_baxter_iii/2010/02/how_to_safely_add__modify_servlet_request_parameter_values) directly using a [servletfilter](https://www.mkyong.com/spring-mvc/how-to-register-a-servlet-filter-in-spring-mvc/) or a spring [filter](https://www.baeldung.com/spring-boot-add-filter)) before I call the repository. In this form you don't have to circumvent the suggested paging solution. – m4gic Aug 30 '18 at 12:18
  • [This](https://stackoverflow.com/questions/51439118/spring-boot-2-0-0-pagination-maven-and-hibernate) is another solution, this time with normal JPARepository, without PageableHandlerMethodArgumentResolver – m4gic Aug 30 '18 at 12:18
  • excuse me , i want from front end page to send paramter 1 not zero , i want to start pagination with zero , i read your example and it's not custom pagination value , it's normal pagination – Salah Atwa Aug 30 '18 at 12:26
  • What I am trying to tell you, that you can modify either your client code to support standand pagination, or, by doing the request manipulations above, the server side to support your custom pagination. In my examples above I suggested the latter. However, if you could tell us some details what client technology requires you to try to implement custom pagination, someone else may know how to modify it to be able to use it with spring's standar pagination. – m4gic Aug 30 '18 at 12:30
  • i'm using angular 6 in my front end , but i wont to edit my front end code , i need to custom pagination value to just start with 1 – Salah Atwa Aug 30 '18 at 12:31
  • In this case, you can try to get your code to work somehow, or, you can do what I suggested with either the ServletRequest or with the incoming Pageable (@see the working example in my first comment). – m4gic Aug 30 '18 at 12:33

0 Answers0