Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Implementation of paging query by JPA user-defined sql

Shulou Source: shulou.com Published: 2022-06-03 05:21:57 11月24日 Update

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

Tags: Reference query Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Shulou Technology Huawei MariaDB