本文整理汇总了Java中org.springframework.data.domain.Pageable.getOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Pageable.getOffset方法的具体用法?Java Pageable.getOffset怎么用?Java Pageable.getOffset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.domain.Pageable
的用法示例。
在下文中一共展示了Pageable.getOffset方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createOptions
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
/**
* build options map for tarantool paging request
* @param pageable spring-data pageable (page size and offset provider)
* @param iterator tarantool iterator
* @return map to push into tarantool
*/
public static Map<String, Object> createOptions(Pageable pageable, Iterator iterator) {
Map<String, Object> options = new HashMap<>();
if (pageable.getPageSize() != Integer.MAX_VALUE) {
options.put("limit", pageable.getPageSize());
}
if (pageable.getOffset() != 0) {
options.put("offset", pageable.getOffset());
}
if (iterator != null) {
options.put("iterator", iterator.getValue());
}
return options;
}
示例2: fromPageable
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
private <T> Stream<T> fromPageable(Page<T> result, Pageable pageable,
Query<T, ?> query) {
List<T> items = result.getContent();
int firstRequested = query.getOffset();
int nrRequested = query.getLimit();
int firstReturned = (int) pageable.getOffset();
int firstReal = firstRequested - firstReturned;
int afterLastReal = firstReal + nrRequested;
if (afterLastReal > items.size()) {
afterLastReal = items.size();
}
return items.subList(firstReal, afterLastReal).stream();
}
示例3: findAll
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
/**
* 分页条件查询
* @param cq 条件
* @param pageable 分页信息
* @param <T> 领域类(实体类)范型
* @return 分页结果
*/
public static <T> Page<T> findAll(CriteriaQuery<T> cq, Pageable pageable) {
Class<T> domainClass = cq.getResultType();
Root<T> root;
if (CollectionUtils.isEmpty(cq.getRoots())) {
root = cq.from(domainClass);
} else {
root = (Root<T>) cq.getRoots().iterator().next();
}
EntityManager em = getEntityManager(domainClass);
if (pageable == null) {
List<T> list = findAll(cq);
return new PageImpl<T>(list);
} else {
Sort sort = pageable.getSort();
cq.orderBy(QueryUtils.toOrders(sort, root, em.getCriteriaBuilder()));
TypedQuery<T> query = em.createQuery(cq);
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
Long total = count(cq);
List<T> content = total > pageable.getOffset() ? query.getResultList() : Collections.<T> emptyList();
return new PageImpl<T>(content, pageable, total);
}
}
示例4: paging
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public <T> Page<T> paging(Pageable pageable) {
if (parent != null) {
applyPredicateToCriteria(sq);
return parent.paging(pageable);
}
List<T> list;
if (pageable == null) {
list = list();
return new PageImpl<T>(list);
} else {
Sort sort = pageable.getSort();
if (sort != null) {
orders.addAll(QueryUtils.toOrders(sort, root, cb));
}
applyPredicateToCriteria(criteria);
TypedQuery<?> query = em.createQuery(criteria);
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
Long total = JpaUtil.count(criteria);
List<T> content = Collections.<T> emptyList();
if (total > pageable.getOffset()) {
content = transform(query, false);
}
return new PageImpl<T>(content, pageable, total);
}
}
示例5: readPage
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
protected Page<T> readPage(final TypedQuery<T> query, final Pageable pageable, final Specification<T> spec) {
query.setFirstResult(pageable.getOffset());
query.setMaxResults(pageable.getPageSize());
final Long total = QueryUtils.executeCountQuery(getCountQuery(spec));
final List<T> content = total > pageable.getOffset() ? query.getResultList() : Collections.<T>emptyList();
if (total > maximumRecords) {
return new CustomPageImpl<>(content, pageable, maximumRecords, String.format(ERROR_MESSAGE, maximumRecords));
} else {
return new PageImpl<>(content, pageable, total);
}
}
示例6: getPageQuery
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public String getPageQuery(Pageable pageable) {
int offset = pageable.getOffset()+1;
return generateRowNumSqlQueryWithNesting(getSelectClause(), false, "TMP_ROW_NUM >= "
+ offset + " AND TMP_ROW_NUM < " + (offset+pageable.getPageSize()));
}
示例7: getPageQuery
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public String getPageQuery(Pageable pageable) {
int offset = pageable.getOffset() + 1;
return generateRowNumSqlQueryWithNesting(getSelectClause(), false,
"TMP_ROW_NUM BETWEEN " + offset + " AND " + (offset + pageable.getPageSize()));
}
示例8: find
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public <X> Page<X> find(String hql, String countHql, Map<String, ?> params, Pageable pageable, Class<X> clazz) {
long total = count(countHql, params);
List<X> content = total > pageable.getOffset() ? find(hql, params, pageable, clazz) : Lists.newArrayList();
return new PageImpl<>(content, pageable, total);
}
示例9: findByNative
import org.springframework.data.domain.Pageable; //导入方法依赖的package包/类
@Override
public <X> Page<X> findByNative(String sql, String countSql, List<?> params, Pageable pageable, Class<X> clazz) {
long total = countByNative(countSql, params);
List<X> content = total > pageable.getOffset() ? findByNative(sql, params, pageable, clazz) : Lists.newArrayList();
return new PageImpl<>(content, pageable, total);
}