Mysql
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "select * from users order by id desc
#pageable
",
countQuery = "select count(*) from users",
nativeQuery = true)
Page<User> findAllRandom(Pageable pageable);
}
如果 pageable 对象中有排序,这里可以去掉
order by排序。
countQuery可以省略。
H2
H2 数据库中要将
#pageable
改成
-- #pageable
形式。
Oracle
Oracle 数据库中要将
#pageable
改成 ?#{#pageable} 形式。