Implementation of paging query by JPA user-defined sql
CustomerRepository.java
@ 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
/ / call custom sqlPage pageObjectList = customerRepos.findAllByPageable (pageService.getPageable (1,1, null))
ORDER BY? # {# pageable} must be added, otherwise an error is reported:
Caused by: org.springframework.data.jpa.repository.query.InvalidJpaQueryMethodException:
Cannot use native queries with dynamic sorting and/or pagination in...
Reference: https://www.cnblogs.com/jiangxiaoyaoblog/p/5635152.html