本文整理了Java中org.springframework.data.domain.Pageable
类的一些代码示例,展示了Pageable
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Pageable
类的具体详情如下:
包路径:org.springframework.data.domain.Pageable
类名称:Pageable
[英]Abstract interface for pagination information.
[中]分页信息的抽象接口。
代码示例来源:origin: spring-projects/spring-data-redis
@Override
public <S extends T> Page<S> findAll(Example<S> example, Pageable pageable) {
Assert.notNull(pageable, "Pageable must not be null!");
RedisOperationChain operationChain = createQuery(example);
KeyValueQuery<RedisOperationChain> query = new KeyValueQuery<>(operationChain);
Iterable<T> result = keyValueTemplate.find(
query.orderBy(pageable.getSort()).skip(pageable.getOffset()).limit(pageable.getPageSize()),
entityInformation.getJavaType());
long count = operationChain.isEmpty() ? keyValueTemplate.count(entityInformation.getJavaType())
: keyValueTemplate.count(query, entityInformation.getJavaType());
List<S> list = new ArrayList<>();
for (T t : result) {
list.add((S) t);
}
return new PageImpl<>(list, pageable, count);
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testDoReadFirstReadNoResults() throws Exception {
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<>()));
assertNull(reader.doRead());
Pageable pageRequest = pageRequestContainer.getValue();
assertEquals(0, pageRequest.getOffset());
assertEquals(0, pageRequest.getPageNumber());
assertEquals(1, pageRequest.getPageSize());
assertEquals("id: ASC", pageRequest.getSort().toString());
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Configures the {@link Pageable} to use.
*
* @param pageable must not be {@literal null}
* @return
*/
public NearQuery with(Pageable pageable) {
Assert.notNull(pageable, "Pageable must not be 'null'.");
if (pageable.isPaged()) {
this.num = pageable.getOffset() + pageable.getPageSize();
this.skip = pageable.getOffset();
}
return this;
}
代码示例来源:origin: ctripcorp/apollo
public PageDTO(List<T> content, Pageable pageable, long total) {
this.total = total;
this.content = content;
this.page = pageable.getPageNumber();
this.size = pageable.getPageSize();
}
代码示例来源:origin: spring-projects/spring-data-mongodb
/**
* Sets the given pagination information on the {@link Query} instance. Will transparently set {@code skip} and
* {@code limit} as well as applying the {@link Sort} instance defined with the {@link Pageable}.
*
* @param pageable
* @return
*/
public Query with(Pageable pageable) {
if (pageable.isUnpaged()) {
return this;
}
this.limit = pageable.getPageSize();
this.skip = pageable.getOffset();
return with(pageable.getSort());
}
代码示例来源:origin: spring-cloud/spring-cloud-dataflow
@Override
public List<JobInstanceExecutions> listTaskJobInstancesForJobName(Pageable pageable, String jobName)
throws NoSuchJobException {
Assert.notNull(pageable, "pageable must not be null");
Assert.notNull(jobName, "jobName must not be null");
List<JobInstanceExecutions> taskJobInstances = new ArrayList<>();
for (JobInstance jobInstance : jobService.listJobInstances(jobName, getPageOffset(pageable),
pageable.getPageSize())) {
taskJobInstances.add(getJobInstanceExecution(jobInstance));
}
return taskJobInstances;
}
代码示例来源:origin: org.springframework.data/spring-data-keyvalue
@Override
public Page<T> findAll(Pageable pageable) {
Assert.notNull(pageable, "Pageable must not be null!");
if (pageable.isUnpaged()) {
List<T> result = findAll();
return new PageImpl<>(result, Pageable.unpaged(), result.size());
}
Iterable<T> content = operations.findInRange(pageable.getOffset(), pageable.getPageSize(), pageable.getSort(),
entityInformation.getJavaType());
return new PageImpl<>(IterableConverter.toList(content), pageable,
this.operations.count(entityInformation.getJavaType()));
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Binds the parameters to the given query and applies special parameter types (e.g. pagination).
*
* @param query must not be {@literal null}.
* @param values values of method parameters to be assigned to the query parameters.
*/
Query bindAndPrepare(Query query, Object[] values) {
Assert.notNull(query, "Query must not be null!");
ParametersParameterAccessor accessor = new ParametersParameterAccessor(parameters, values);
Query result = bind(query, values);
if (!useJpaForPaging || !parameters.hasPageableParameter() || accessor.getPageable().isUnpaged()) {
return result;
}
result.setFirstResult((int) accessor.getPageable().getOffset());
result.setMaxResults(accessor.getPageable().getPageSize());
return result;
}
}
代码示例来源:origin: spring-projects/spring-data-elasticsearch
private SearchRequest prepareSearch(Query query, Optional<QueryBuilder> builder) {
Assert.notNull(query.getIndices(), "No index defined for Query");
Assert.notNull(query.getTypes(), "No type defined for Query");
if (query.getPageable().isPaged()) {
startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();
sourceBuilder.size(query.getPageable().getPageSize());
代码示例来源:origin: apache/servicemix-bundles
/**
* Returns the current {@link Sort} or the given one if the current one is unsorted.
*
* @param sort must not be {@literal null}.
* @return
*/
default Sort getSortOr(Sort sort) {
Assert.notNull(sort, "Fallback Sort must not be null!");
return getSort().isSorted() ? getSort() : sort;
}
代码示例来源:origin: SpringDataElasticsearchDevs/spring-data-elasticsearch
@Override
public final <T extends Query> T setPageable(Pageable pageable) {
Assert.notNull(pageable);
this.pageable = pageable;
return (T) this.addSort(pageable.getSort());
}
代码示例来源:origin: com.github.derjust/spring-data-dynamodb
public UnpagedPageImpl(@NonNull List<T> content, long total) {
Assert.notNull(content, "content must not be null!");
this.pageable = Pageable.unpaged();
this.content = content;
this.total = total;
}
代码示例来源:origin: org.springframework.data/spring-data-r2dbc
DefaultSelectSpecSupport(String table) {
Assert.hasText(table, "Table name must not be null!");
this.table = table;
this.projectedFields = Collections.emptyList();
this.sort = Sort.unsorted();
this.page = Pageable.unpaged();
}
代码示例来源:origin: org.springframework.data/spring-data-keyvalue
@Override
public Page<T> findAll(Predicate predicate, Pageable pageable) {
AbstractCollQuery<T, ?> query = prepareQuery(predicate);
if (pageable.isPaged() || pageable.getSort().isSorted()) {
query.offset(pageable.getOffset());
query.limit(pageable.getPageSize());
if (pageable.getSort().isSorted()) {
query.orderBy(toOrderSpecifier(pageable.getSort(), builder));
}
}
return new PageImpl<>(query.fetchResults().getResults(), pageable, count(predicate));
}
代码示例来源:origin: spring-projects/spring-data-rest
@Override
public Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
Pageable pageable = delegate.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);
if (pageable == null || pageable.getSort() == null) {
return pageable;
}
Sort translated = translator.translateSort(pageable.getSort(), methodParameter, webRequest);
return PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), translated);
}
}
代码示例来源:origin: apache/ignite
/**
* Add a dynamic part of a query for the pagination support.
*
* @param sql Builder instance.
* @param pageable Pageable instance.
* @return Builder instance.
*/
public static StringBuilder addPaging(StringBuilder sql, Pageable pageable) {
if (pageable.getSort() != null)
addSorting(sql, pageable.getSort());
sql.append(" LIMIT ").append(pageable.getPageSize()).append(" OFFSET ").append(pageable.getOffset());
return sql;
}
代码示例来源:origin: debop/hibernate-redis
@Override
public <T> Page<T> getPage(Class<T> clazz, Query query, Pageable pageable, HibernateParameter... parameters) {
long totalItemCount = count(query, parameters);
List<T> items = find(clazz, query, pageable.getPageNumber() * pageable.getPageSize(), pageable.getPageSize(), parameters);
return new PageImpl<T>(items, pageable, totalItemCount);
}
代码示例来源:origin: excelsior-oss/restler
@Override
protected String getPathPart(Object[] args) {
Pageable page = (Pageable) args[0];
return "?page=" + page.getPageNumber() + "&size=" + page.getPageSize() + "&sort=" + page.getSort().toString().replace(": ", ",");
}
代码示例来源:origin: debop/hibernate-redis
@Override
public <T> Page<T> getPage(Class<T> clazz, Criteria criteria, Pageable pageable) {
Criteria countCriteria = HibernateTool.copyCriteria(criteria);
long totalItemCount = count(countCriteria);
List<T> items = find(clazz, criteria,
pageable.getPageNumber() * pageable.getPageSize(),
pageable.getPageSize(),
CriteriaTool.toOrders(pageable.getSort()).toArray(new Order[0]));
return new PageImpl<T>(items, pageable, totalItemCount);
}
代码示例来源:origin: spring-projects/spring-data-jpa
/**
* Reads the given {@link TypedQuery} into a {@link Page} applying the given {@link Pageable} and
* {@link Specification}.
*
* @param query must not be {@literal null}.
* @param domainClass must not be {@literal null}.
* @param spec can be {@literal null}.
* @param pageable can be {@literal null}.
* @return
*/
protected <S extends T> Page<S> readPage(TypedQuery<S> query, final Class<S> domainClass, Pageable pageable,
@Nullable Specification<S> spec) {
if (pageable.isPaged()) {
query.setFirstResult((int) pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
}
return PageableExecutionUtils.getPage(query.getResultList(), pageable,
() -> executeCountQuery(getCountQuery(spec, domainClass)));
}
内容来源于网络,如有侵权,请联系作者删除!