From the course: Creating Your First Spring Boot Microservice
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Paging and sorting DTOs
From the course: Creating Your First Spring Boot Microservice
Paging and sorting DTOs
- [Instructor] One last topic I'd like to cover is how to add paging and sorting to a DTO-based API. The first thing we're going to do is add a new method to TourRatingRepository. That will return a page of tour ratings. So at the bottom of this, we're going to say Page of TourRatings findByPkTourId and we're going to overload that not just with the tourId but we're also going to have the Pageable parameter passed in. And then back in our TourRatingController, so we're going to take the existing get method for get All Tour Ratings for a tour and have that return a page of data. So we'll have the return as a Page of RatingDtos, not TourRatings. And then we pass in Pagable. And we're still going to verify the tourId but this code is going to change. So what we have here now starting on line 69 is we're going to invoke the TourRatingRepository findByPkTourId where we pass in the tourId and the Pagable object…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.