MySQL
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
可以省略。
H2
H2 数据库中要将 \n#pageable\n
改成 \n-- #pageable\n
形式。
如果长时间无法加载,请针对 disq.us | disquscdn.com | disqus.com 启用代理