r/SpringBoot • • Sep 13 '26

Question Pagination in Springboot

If you're ar working on springboot project in you company/job. How does your team do pagination in your project as they have large datasets. I am currently learning springboot and curious to know how it's done withel large datasets.

55 Upvotes

33 comments sorted by

View all comments

Show parent comment

0

u/kamen1991 Sep 13 '26 edited Sep 13 '26

And you expose your whole database entities schema. :) The first thing to do is to decouple the spring based classes, they're implementation details. Returning DTOs from the controller is an absolute requirement. For parameters use query params, page, size, sort etc. and then you can map them to Spring page, Specification, Query params or whatever is your implementation. That way you can refactor your codebase without breaking any of your clients, you can even replace your database with redis or whatever you want if the business decides they want to move away from relational database.

9

u/wimdeblauwe Sep 13 '26

I never said that T was an entity. It should indeed be a DTO in the controller. Page has a map() method to map the entity from the service/repository to a DTO.