Pagination in Spring Data JPA (limit and offset)

后端 未结 7 1059
眼角桃花
眼角桃花 2020-12-02 08:54

I want the user to be able to specify the limit (the size of the amount returned) and offset (the first record returned / index returned) in my query method.

Here a

7条回答
  •  甜味超标
    2020-12-02 09:25

    Here you go:

    public interface EmployeeRepository extends JpaRepository {
    
        @Query(value="SELECT e FROM Employee e WHERE e.name LIKE ?1 ORDER BY e.id offset ?2 limit ?3", nativeQuery = true)
        public List findByNameAndMore(String name, int offset, int limit);
    }
    

提交回复
热议问题