本文整理汇总了Java中org.springframework.data.jpa.repository.JpaSpecificationExecutor类的典型用法代码示例。如果您正苦于以下问题:Java JpaSpecificationExecutor类的具体用法?Java JpaSpecificationExecutor怎么用?Java JpaSpecificationExecutor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JpaSpecificationExecutor类属于org.springframework.data.jpa.repository包,在下文中一共展示了JpaSpecificationExecutor类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: selectFrom
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; //导入依赖的package包/类
public static <ENTITY, REPO extends JpaRepository<ENTITY, ?> & JpaSpecificationExecutor>
SpecificationBuilder<ENTITY> selectFrom(REPO repository) {
SpecificationBuilder<ENTITY> builder = new SpecificationBuilder<>();
builder.repository = repository;
builder.specification = new SpecificationImpl();
return builder;
}
示例3: selectDistinctFrom
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; //导入依赖的package包/类
public static <ENTITY, REPO extends JpaRepository<ENTITY, ?> & JpaSpecificationExecutor>
SpecificationBuilder<ENTITY> selectDistinctFrom(REPO repository) {
SpecificationBuilder<ENTITY> builder = selectFrom(repository);
builder.distinct();
return builder;
}
示例4: groupRelations
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; //导入依赖的package包/类
@Nonnull
public static <T, U> Map<T, List<U>> groupRelations(
@Nonnull final Collection<? extends T> objects,
@Nonnull final SingularAttribute<? super U, T> singularAttribute,
@Nonnull final JpaSpecificationExecutor<U> repository) {
return groupRelations(objects, singularAttribute, repository, null, null);
}
示例5: groupRelationsById
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; //导入依赖的package包/类
@Nonnull
public static <ID extends Serializable, T extends HasID<ID>, U> Map<ID, List<U>> groupRelationsById(
@Nonnull final Collection<? extends T> objects,
@Nonnull final SingularAttribute<? super U, T> singularAttribute,
@Nonnull final JpaSpecificationExecutor<U> repository) {
return groupRelationsById(objects, singularAttribute, repository, null, null);
}
示例6: 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,
final boolean letFunctionThrowExceptionOnEmptyResult) {
return createInverseMappingFunction(
objects, singularAttribute, repository, null, letFunctionThrowExceptionOnEmptyResult);
}
示例7: 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));
}