JPA自定义sql实现分页查询

CustomerRepository.java

成都创新互联是一家专注于网站设计制作、成都网站设计与策划设计,凤台网站建设哪家好?成都创新互联做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:凤台等地区。凤台做网站价格咨询:18982081108

@Query(nativeQuery = true, value = "select * from adm_sys_customer ORDER BY ?#{#pageable}",
countQuery = "select count(*) from adm_sys_customer")
Page findAllByPageable(Pageable pageable);

CustomerServiceImpl.java

//调用自定义sql
Page 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实现分页查询
本文网址:http://hbruida.cn/article/gdjoej.html