溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

JPA自定義sql實現(xiàn)分頁查詢

發(fā)布時間:2020-07-09 01:07:20 來源:網(wǎng)絡(luò) 閱讀:21581 作者:夢Scarlett 欄目:軟件技術(shù)

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

//調(diào)用自定義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

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI