我们可以做 List<MyInfo> findAll(List<Integer> ids)
在 Spring 数据中。我如何将其与分页结合起来?
关于:
findAll(ids, pageRequest);
我尝试了一些创建规范并使用它的方法,但我做错了:
public class MySpecs {
public static Specification<MyInfo> idsIn(final List<Integer> ids)
{
return new Specification<MyInfo>() {
@Override
public Predicate toPredicate(Root<MyInfo> root,
CriteriaQuery<?> query, CriteriaBuilder cb) {
return root.get("id").in(ids);
}
};
}
}
myRepo.findAll(MySpecs.isIn(ids),pageRequest)
谢谢
最佳答案
最简单的方法是简单地声明一个查询方法,如下所示:
interface MyInfoRepository extends Repository<MyInfo, Integer> {
Page<MyInfo> findByIdIn(List<Integer> ids, Pageable pageable);
}
关于spring - Spring Data 中的 findAll Iterable AND Pageable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22144943/