I am new to Spring Data JPA and wondering if there is a way to retrieve data from successive pages in spring data JPA paging?
1 Answers
You can refer to Pageable Interface in Spring data JPA.
https://www.baeldung.com/spring-data-jpa-pagination-sorting
https://docs.spring.io/spring-data/jpa/docs/2.2.7.RELEASE/reference/html/#reference
As per the request, let's see with the example.
- Consider you have Customer as an Entity and you want to generate Paginated list of the Customer list.
You need to create a repository interface.
@Repository public interface CustomerRepository extends JpaRepository { }
From Service, you can call this repository method.
@Transactional(readOnly = true) public Page findAll(Pageable pageable) { log.debug("Request to get all Customers"); return customerRepository.findAll(pageable); }
From controller,
Page page = customerService.findAll(pageable);
From your webApp, you can query a GET request with following params.
queryParams: { page: this.page, size: this.itemsPerPage, sort: 'id,asc' }

- 484
- 2
- 12
-
Thank you. Would be great if you could please provide the implementation (hopefully not more than a couple of lines) rather than pointing to external links as there are chances of losing track – Prem Kumar Easwaran May 09 '20 at 18:52
-
The references are the means to provide much deeper guidance. – Dharmendra Vishwakarma May 10 '20 at 10:48