'page size in spring boot to get total size
the default size of page is 20, I want to be able to get all elements from endpoint url.
to get 30 elements I set size like below :
http://localhost:8080/api/invoices?page=0&size=30
I don't want to change the default value of page size, I need to get total size from url but I didn't found how to set this. Thank you in advance
Solution 1:[1]
You can get size
i.e. page size and page
i.e. page number from URL using @RequestParam
@GetMapping
public List<Object> getInvoices(
@RequestParam(required = false, value = "page", defaultValue = "0") Integer page,
@RequestParam(required = false, value = "size", defaultValue = "20") Integer size) {
return <return response from here>
}
Here, default page size is 20 and page number is 0.
From UI side you just have to send values like this way,
http://localhost:8080/api/invoices?page=0&size=30
Note: I marked both the parameters as not required so that you can also use below URL to get all the invoices.
http://localhost:8080/api/invoices
So, change this as per your requirement.
For more information refer https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html
Thanks
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 | Ganesh Thorat |