我的查询是这样的
@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 对象作为参数传递。假设您阅读了链接的答案,并且知道您的存储库应该扩展 JpaRepository
或 PagingAndSortingRepository
,它看起来像这样:
@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/