使用JPA规范指定结果限制 [英] Specifying Result limit using JPA Specification

查看:70
本文介绍了使用JPA规范指定结果限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过Spring-Data-JPA规范使用limitsetMaxResults? 我可以通过CriteriaJPQL使用它,但是我只需要通过规范即可. 规格带有CriteriaQuery,而不是Query.因此,没有setMaxResults方法.

Is there possibility to use limit or setMaxResults using Spring-Data-JPA Specification? I can use it via Criteria or JPQL, but I need only via specifications. Specifications have CriteriaQuery, not a Query. So, there is no setMaxResults method.

推荐答案

我认为您只有两个选择:

I think you only have two options:

在您的规范中使用Pageable:

Use Pageable with your Specification:

Pageable limit = new PageRequest(0,10);
repo.findAll(spec, limit);

或执行类似的解决方法: https://gist.github.com/tcollins/0ebd1dfa78028ecdef0b . @tcollins的所有功劳

or do a workaround like this one: https://gist.github.com/tcollins/0ebd1dfa78028ecdef0b. All the credits to @tcollins

这篇关于使用JPA规范指定结果限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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