gpt4 book ai didi

java - spring-data 中的分页

转载 作者:行者123 更新时间:2023-11-29 19:12:09 24 4
gpt4 key购买 nike

我在使用分页查询数据库时有一个要求。分页时,我将为查询提供页面大小和页面索引,如下所示,

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为null的所有数据,无论查询中的值大小如何。我的意思是,当索引为零时,不应应用分页,并且我应该获取 tp_completed_at 为空的所有条目。并且,当索引的值不为 0 时,应应用分页。请帮忙

最佳答案

您可以使用 Pageable 来做到这一点。 PageRequest(页面,大小)

Pageable page = new PageRequest(0, 10);

例如:

Page<Incident> findByProblemId(Long problemId, Pageable page);

就你的情况而言,countQuery =“...count(distinct tp.*) ...无限制”

@Query(value = "your existing Query without limit ", countQuery = "countQuery", nativeQuery = true)
getData(@Param("workStreamId") String workStreamId, @Param("userId") String userId, Pageable page);

关于java - spring-data 中的分页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42994470/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com