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
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/193358.html