I use PagingAndSortingRepository and findAll(Pageable pageable) method to paging my data. I think that there is no way to provide any condition. For example sometime I want select and paging addresses where city=NY. Is there any way to provide condition and paging simultaneously?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
The
PagingAndSortingRepository
just adds the very basic CRUD methods in pagination mode. As the reference documentation describes, you can simply add aPageable
parameter to any query method you define to achieve pagination of this query.The first method will return a
Page
containing the page metadata like total elements available etc. To calculate this data it will trigger an additional count query for the query derived. The second query method returns the plain sliced result set without the count query being executed.For Pagination you need 2 methods like getCount(Pageable pageable) and findAll(Pageable pageable)
Utilizing this functionality in Hibernate, however, is trivial. If you have any HQL query you can simply do this:
Likewise, if you have a Criteria query, it's effectively the same thing: