'Spring boot return all records if no page information passed

I have an API which is something like this

https://[HOSTNAME]/products?page=0&size=20

It returns 20 records. If I remove this information

https://[HOSTNAME]/products

then by default it returns only 10 records.

Backend API implementation is

public ResponseEntity<?> getProducts(
      @PathVariable (name="objectId") UUID categoryId,
      // ..other parameters
      @PageableDefault(page = 0) Pageable page) {

}

I am using Pageable for fetching data from database

productRepository
    .findByproductInAndStateIn(productIds, states, pageable);

What I am looking for is when I hit this url, then it should return all records

https://[HOSTNAME]/products

I tried to find the way but couldn't find any solution. Is there any way to achieve the same?



Solution 1:[1]

@PageableDefault has the following implementation

public @interface PageableDefault {

    int value() default 10;
    int size() default 10;
    int page() default 0;
    String[] sort() default {};
    Direction direction() default Direction.ASC;
}

So if you don't specify size, you are getting 10 records.

Either remove @PageableDefault annotation and specify the following property in your .yml file spring.data.rest.default-page-size = 99999999

Or pass size value in @PageableDefault like this

@PageableDefault(size = Integer.MAX_VALUE, page = 0)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Buzevich