我在使用分頁查詢數據庫時有要求。 雖然分頁,我給頁面大小和頁索引到查詢如下所示,春季分頁數據
select distinct tp.* from kat_task_property tp inner join kat_task_to_workstream ttw on ttw.ttw_frn_task_id = tp.tp_frn_task_id and ttw.ttw_frn_workstream_id= :workStreamId and ttw.ttw_ended_by is null and tp.tp_ended_by is null and tp.tp_is_active=true and ttw.ttw_is_active=true left join kat_user_to_task_order kto on ttw.ttw_id = kto.uto_frn_task_to_workstream_id and kto.uto_frn_user_id = :userId order by tp.tp_completed_at ,kto.uto_order limit :index, :size
樣品結果將是,
tp_id tp_completed_at
1 2017-02-27 06:47:52
2 null
3 null
4 2017-03-14 12:59:24
5 null
6 null
7 null
我的要求是當指數是在查詢0,無論查詢中的值大小如何,我都應該獲取tp_completed_at爲空的所有數據。我的意思是,當索引爲零時,不應該使用分頁,我應該使用tp_completed_at獲取所有條目爲空。而且,如果指數具有0以外的值,則應該應用分頁。請幫助
我可以使用可分頁對象與本地查詢 – Virat
@Sandesha當然可以,但你必須定義計數這樣的查詢@Query(value =「SELECT * FROM USERS WHERE LASTNAME =?1」, countQuery =「SELECT count(*)FROM USERS WHERE LASTNAME =?1」, nativeQuery = true) – lucid
我從來沒有使用過Pageable。如何在我的查詢中使用?請幫助 – Virat