本文整理汇总了Java中org.springframework.data.jpa.repository.JpaSpecificationExecutor.findAll方法的典型用法代码示例。如果您正苦于以下问题:Java JpaSpecificationExecutor.findAll方法的具体用法?Java JpaSpecificationExecutor.findAll怎么用?Java JpaSpecificationExecutor.findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.jpa.repository.JpaSpecificationExecutor
的用法示例。
在下文中一共展示了JpaSpecificationExecutor.findAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: groupRelationsInternal
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; //导入方法依赖的package包/类
private static <T, U, V> Map<V, List<U>> groupRelationsInternal(
@Nonnull final Collection<? extends T> objects,
@Nonnull final Specification<U> inSpec,
@Nonnull final JpaSpecificationExecutor<U> repository,
@Nonnull final Function<? super U, ? extends V> keyMapper,
@Nullable final Specification<U> constraint,
@Nullable final Sort sortCriteria) {
Objects.requireNonNull(objects, "objects must not be null");
Objects.requireNonNull(inSpec, "inSpec must not be null");
Objects.requireNonNull(repository, "repository must not be null");
if (objects.isEmpty()) {
return new HashMap<>(0);
}
final Specification<U> compoundSpec =
constraint == null ? inSpec : Specifications.where(inSpec).and(constraint);
final List<U> list = sortCriteria != null
? repository.findAll(compoundSpec, sortCriteria) : repository.findAll(compoundSpec);
return F.nullSafeGroupBy(list, keyMapper);
}
示例2: createInverseMappingFunction
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; //导入方法依赖的package包/类
public static <ID extends Serializable, T extends HasID<ID>, U> Function<T, List<U>> createInverseMappingFunction(
@Nonnull final Collection<? extends T> objects,
@Nonnull final SingularAttribute<? super U, T> singularAttribute,
@Nonnull final JpaSpecificationExecutor<U> repository,
@Nullable final Specification<U> constraint,
final boolean letFunctionThrowExceptionOnEmptyResult) {
Objects.requireNonNull(objects, "objects must not be null");
Objects.requireNonNull(singularAttribute, "singularAttribute must not be null");
Objects.requireNonNull(repository, "repository must not be null");
if (Iterables.isEmpty(objects)) {
return input -> Collections.emptyList();
}
final Specification<U> relationSpec = inCollection(singularAttribute, objects);
final Specification<U> compoundSpec =
constraint != null ? JpaSpecs.and(relationSpec, constraint) : relationSpec;
final List<U> relatedObjects = repository.findAll(compoundSpec);
if (relatedObjects.isEmpty()) {
return input -> Collections.emptyList();
}
final Map<ID, List<U>> index =
F.groupByIdAfterTransform(relatedObjects, CriteriaUtils.jpaProperty(singularAttribute));
final Function<ID, List<U>> indexFunc =
letFunctionThrowExceptionOnEmptyResult ? forMap(index) : forMap(index, null);
return indexFunc.compose(F::getId);
}
示例3: getPage
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; //导入方法依赖的package包/类
/**
* 根据 customSpecification,进行分页查询。
* <p>
* findAll() 方法,会进行两次查询,先做 count 查询,之后是具体查询,所以 Page 中包含了总数和具体查询结果集
*
* @param repository 查询器
* @param currentPageNo 当前页,实际对应 jqgrid 传递过来的 page 参数,jqgrid 规定起始页为 1
* @param pageSize 页面可显示行数
* @param sort
* @param customSpecification 除了 jqgrid 传递过来的查询条件外,自己又附加查询条件,与 filters AND 关系的查询条件,specification 的构造符合 SearchFilter 写法,详见示例项目。
* customSpecification 中指定的属性名称应该是待查询的 entity 中的属性名称,并且用改 entity 的 repository 进行查询
* @return
*/
public static Page getPage(JpaSpecificationExecutor repository, int currentPageNo, int pageSize, Sort sort, Specification customSpecification) {
//jpa 中起始页为 0,但传递过来的参数 currentPageNo 不能小于1
Assert.isTrue(currentPageNo >= 1, "currentPageNo 需要 >= 1 ");
currentPageNo = currentPageNo - 1;
return repository.findAll(customSpecification, new PageRequest(currentPageNo, pageSize, sort));
}