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.
我在我的项目中使用Spring Data JPA和RDBMS。我有一个要求,我必须从具有最新日期的表中获取数据库中的单个记录。为此,我需要使用限制和按功能排序或使用子查询。但是,我想知道我是否希望不使用NamedQuery是否有一种方法可以使用Spring Data JPA和QueryDSL来实现。
2 个解决方案
#1
11
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 limit
results.
不应该QueryDslPredicateExecutor.findAll(谓词谓词,可分页可分页)为你做的伎俩?您可以提交新的PageRequest(0,限制),从而获得第一个限制结果。
#2
1
How about using the MIN and MAX function to attain this.
如何使用MIN和MAX功能来实现这一目标。
SELECT MAX(objDate) FROM Object
#1
11
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 limit
results.
不应该QueryDslPredicateExecutor.findAll(谓词谓词,可分页可分页)为你做的伎俩?您可以提交新的PageRequest(0,限制),从而获得第一个限制结果。
#2
1
How about using the MIN and MAX function to attain this.
如何使用MIN和MAX功能来实现这一目标。
SELECT MAX(objDate) FROM Object