0

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 Answers1

0

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.

  1. Consider you have Customer as an Entity and you want to generate Paginated list of the Customer list.
  2. You need to create a repository interface.

    @Repository public interface CustomerRepository extends JpaRepository { }

  3. 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); }

  4. From controller,

    Page page = customerService.findAll(pageable);

  5. From your webApp, you can query a GET request with following params.

    queryParams: { page: this.page, size: this.itemsPerPage, sort: 'id,asc' }