Q:

How use JpaRepository Query for select sorted records starting from :start and number of :count

I have:
public interface EmployeeRepository extends JpaRepository<Employee, Long> {
@Query("select e from Employee e where e.fired = false and e.department.company.id=:company order by e.dateContractEnd asc")
public List<Employee> readEmployeeList(@Param("company") Long company);
}

And the customer navigates through the pages. And I should display:
first page: records starting from 1 and records count - 10,
secound page: records starting from 11 and records count - 10 etc. And all records select from sorting data (order by e.dateContractEnd asc). How to set first record and records count for select in sorting data?

A:

Extend PagingAndSortingRepository and you can use page then. Here is an example for you.
public interface ItTougaoRepository extends JpaRepository<ItTougao, Long>, PagingAndSortingRepository<ItTougao, Long>{
    public Page<ItTougao> findByAcceptedFalseOrderByCreateDateDesc(Pageable pageable);
    public Page<ItTougao> findByAcceptedTrue(Pageable pageable);
    public Page<ItTougao> findByAcceptedTrueOrderByAcceptDateDesc(Pageable pageable);
}

