java Spring Data JpaRepository findAll(Iterable<ID> ids) + findAll(Sort sort)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31107590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Data JpaRepository findAll(Iterable<ID> ids) + findAll(Sort sort)
提问by Channa
With Spring Data JpaRepository is there any capability to get select collection of given Id with some sorting. That mean I need to make enable following query. I have found some solutionapply with @NamedQuery but I can't make enable it because I am using Spring-data-jap 1.4.2.RELEASE. Thanks.
使用 Spring Data JpaRepository 是否可以通过某种排序来获取给定 Id 的选择集合。这意味着我需要启用以下查询。我找到了一些适用于 @NamedQuery 的解决方案,但我无法启用它,因为我使用的是Spring-data-jap 1.4.2.RELEASE。谢谢。
public Iterable<User> findAll(Iterable<Integer> userIds) {
Sort sort = new Sort(Direction.ASC, "name");
Iterable<User> users = userRepository.findAll(userIds, sort);
return users;
}
回答by Oliver Drotbohm
Just declare a query method like this:
只需声明一个这样的查询方法:
public interface UserRepository extends Repository<User, Integer> {
Iterable<User> findByIdIn(Collection<Integer> ids, Sort sort);
}