如何使用order by和限制在Spring数据JPA使用QueryDSL [英] How to use order by and Limit in Spring Data JPA using QueryDSL

查看:1201
本文介绍了如何使用order by和限制在Spring数据JPA使用QueryDSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用了一个RDBMS的Spring Data JPA。我有一个要求,我必须从具有最新日期的表中从数据库获取单个记录。为此,我需要使用限制和排序功能或使用子查询。但是,我想知道如果我不希望使用NamedQuery是有办法使用Spring Data JPA和QueryDSL。

解决方案

不应 QueryDslPredicateExecutor.findAll(谓词谓词,Pageable pageable)为您做伎俩?你可以交出一个新的PageRequest(0,limit),从而得到第一个 limit 结果。 p>

I am using Spring Data JPA with a RDBMS in my project. I have a requirement where I have to fetch a single record from the Database from a table which has the latest date. For this I need to use a limit and order by function OR using sub queries. However, I wished to know if i wish for not to use NamedQuery is there a way I can achieve this using Spring Data JPA and QueryDSL.

解决方案

Shouldn't QueryDslPredicateExecutor.findAll(Predicate predicate, Pageable pageable) do the trick for you? You could hand in a new PageRequest(0, limit) and thus would get back the first limitresults.

这篇关于如何使用order by和限制在Spring数据JPA使用QueryDSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆