Pagination & Sorting in REST API using Spring Data JPA
HTML-код
- Опубликовано: 4 окт 2024
- Learn how to add pagination & sorting to your Spring Boot REST API using Spring Data JPA.
We create a web application using the spring starter (start.spring.io/). We then expose an API for books. We then use Spring Data JPA to add pagination & sorting to the API.
Check out the code on GitHub here: github.com/kri...
Don't forget to Subscribe here: / @krisfoster1
Nice tutorial, thank you! I just had to add "spring.jpa.defer-datasource-initialization=true" in application.properties in order to make it work with Spring Boot 2.6.3
thanks! I just spent the last 30 mins on stack over flow and I thought... "well now let me just check the comment section" haha. Good job.
Wow, thank you so much. Paginating with spring boot seems a lot easier than in Node, even with Prisma ORM.
sweet and simple example to start with this concept, Hope you can cover complex with multiple table example
This was absolutely perfect. Exactly what I was looking for.
hey mate, thanks so much! This video was excellent, very clear and concise
I gotta commend you on your choice of books!! Awesome video too :)
That was very helpful for me! Thanks a lot!
Excellent well done Kris
How would you make it so the getBooks method could be sorted in both descending or ascending order?
Great tutorial! Thank you.
Thank you this was a great tutorial and helped me a lot
How do you see what does the method accepts in 8:11
Thank you, that was helpful :)
Awesome video. Thanks!
Glad you enjoyed, thank you for watching!
Thank you, very helpful for me
Thank you, that was helpful.
Can you show example how to do pagination with Pageable as parameter of controller?
10:24 is there a way to customize what data that pageable return? for example only content, pageNumber and pageSize
I like your accent.
how can i custom the respon of this
"pageable": {
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"offset": 4,
"pageSize": 4,
"pageNumber": 1,
"unpaged": false,
"paged": true
},
"last": true,
"totalPages": 2,
"totalElements": 8,
"size": 4,
"number": 1,
"sort": {
"empty": true,
"sorted": false,
"unsorted": true
},
"numberOfElements": 4,
"first": false,
"empty": false
}
I assume if i have another Requestparameter i can set how many items we get per page right?
He showed that in the video...
Yes. He didn't actually show how to do that in the video but you can do it. You would need another Optional maybe called size or count. Then you would pass that in where he put the hardcoded 5. That 5 was the number he set for count as a default with no option to change it.