Spring Data JPA native query 分頁

Mysql

Spring Data JPA and native queries with paginationmysql

Spring Data and Native Query with paginationspring

public interface UserRepository extends JpaRepository<User, Long> {
    @Query(value = "select * from users order by id desc \n#pageable\n",
            countQuery = "select count(*) from users",
            nativeQuery = true)
    Page<User> findAllRandom(Pageable pageable);
}

若是 pageable 對象中有排序,這裏能夠去掉 order by 排序。
countQuery 能夠省略。sql

H2

H2 數據庫中要將 \n#pageable\n 改爲 \n-- #pageable\n 形式。數據庫

Oracle

Spring Data Jpa本地查詢(帶分頁方式)oracle

Oracle 數據庫中要將 \n#pageable\n 改爲 ?#{#pageable} 形式。dom

相關文章
相關標籤/搜索