本文整理匯總了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));
}