public interface PagingAndSortingRepository<T, ID> extends Repository<T, ID> {
Iterable<T> findAll(Sort sort);
Page<T> findAll(Pageable pageable);
}
public interface TaskRepository extends CrudRepository<Task, Long>, PagingAndSortingRepository<Task, Long> {
}
@GetMapping
public Page<Task> list(@PathVariable("id") long id,
@RequestParam(name = "page", required = true, defaultValue = "0") int page,
@RequestParam(name = "size", required = true, defaultValue = "2") int size) {
Pageable pageable = PageRequest.of(page, size);
return taskRepository.findByProjectId(id, pageable);
}
ex:
.../projects/{project_id}/tasks?page={page_index}&size={page_size}