gpt4 book ai didi

java - 如何使用 Spring Data @query 注释从 mysql 数据库中仅获取 80 行?

转载 作者:太空宇宙 更新时间:2023-11-03 11:55:23 24 4
gpt4 key购买 nike

我的查询是这样的

@Query("select cnt from Content cnt  order by 
CASE WHEN cnt.status = 'rejected' THEN '1'
WHEN cnt.status = 'modified' ELSE cnt.status END ASC")

如何添加限制 0,100 行以添加我的查询

我写的是下面的格式,但是所有的行都是从database

中获取的
@Query("select cnt from Content cnt  
order by CASE WHEN cnt.status = 'rejected' THEN '1'
WHEN cnt.status = 'modified' ELSE cnt.status END ASC limit 0,100")

最佳答案

我写了一个类似帖子的答案here .在您的情况下,查询将是您编写的第一个查询,但您必须将 Pageable 对象作为参数传递。假设您阅读了链接的答案,并且知道您的存储库应该扩展 JpaRepositoryPagingAndSortingRepository,它看起来像这样:

@Query("select cnt from Content cnt 
order by CASE WHEN cnt.status = 'rejected' THEN '1'
WHEN cnt.status = 'modified' ELSE cnt.status END ASC")
public List<Content> getContents(Pageable pageable);

关于java - 如何使用 Spring Data @query 注释从 mysql 数据库中仅获取 80 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33233200/

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