JPA自定义sql实现分页查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JPA自定义sql实现分页查询相关的知识,希望对你有一定的参考价值。
CustomerRepository.java
@Query(nativeQuery = true, value = "select * from adm_sys_customer ORDER BY ?#{#pageable}", countQuery = "select count(*) from adm_sys_customer") Page<Customer> findAllByPageable(Pageable pageable);
CustomerServiceImpl.java
//调用自定义sql Page<Customer> pageObjectList = customerRepos.findAllByPageable(pageService.getPageable(1, 1, null));
ORDER BY ?#{#pageable} 必须加,否则报错:
Caused by: org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException:
Cannot use native queries with dynamic sorting and/or pagination in ...
参考:https://www.cnblogs.com/jiangxiaoyaoblog/p/5635152.html
以上是关于JPA自定义sql实现分页查询的主要内容,如果未能解决你的问题,请参考以下文章