How to query data out of the box using Spring data JPA by both Sort and Pageable?

后端 未结 6 1648
别那么骄傲
别那么骄傲 2020-12-12 12:50

I am trying Spring data JPA in my project. I want to know if there is an out-of-the-box API to query data, by both Sort and Pageable. Of course, I

6条回答
  •  自闭症患者
    2020-12-12 13:40

    in 2020, the accepted answer is kinda out of date since the PageRequest is deprecated, so you should use code like this :

    Pageable page = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("id").descending());
    return repository.findAll(page);
    

提交回复
热议问题