I’m using spring-data jpa 1.1.0.M1 now we were using a much higher version and run into issues with spring-data-mongodb due to spring-data-commons. Because of that we’ve used entity manager in our service for certain query including queries with offset and limit.
Now that we’ve downgraded and everything seems to be fine we would like to maintain everything under repository level when it comes to data access and do much on Business Logic in the Services.
From this documentation i understand that pageable interface is what i need. But the implementation class PageRequest takes page argument. would that mean that my offset becomes the following?
offset = page* limit; => page = offset/limit;
Am I getting it right?
thanks for reading this.
The PageRequest object has a constructor that takes the page and the size. Other constructors allow you to specify additional detail such as the sort direction.
See: Spring PageRequest API Documentation
The
PageRequestis passed as an argument to one of your repositories find methods. In the following example I am getting the first five entries for my blog.In this example the call to the repositories
findAll(PageRequest)method returns aorg.springframework.data.domain.Pageobject. ThePageobject contains several convenient methods that allow information about the underlying ResultSet, such as size and number of pages, to be retrieved.See: Spring Page API Documentation
Given these convenient features, I’m not sure you need to be concerned with managing the offset or the current page since Spring Data is performing this work for you.