org.springframework.data.domain.Pageable.getPageNumber()方法的使用及代码示例

x33g5p2x  于2022-01-26 转载在 其他  
字(10.8k)|赞(0)|评价(0)|浏览(91)

本文整理了Java中org.springframework.data.domain.Pageable.getPageNumber()方法的一些代码示例,展示了Pageable.getPageNumber()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Pageable.getPageNumber()方法的具体详情如下:
包路径:org.springframework.data.domain.Pageable
类名称:Pageable
方法名:getPageNumber

Pageable.getPageNumber介绍

[英]Returns the page to be returned.
[中]返回要返回的页面。

代码示例

代码示例来源: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-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-batch

@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadExhausted() throws Exception {
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  final Object result = new Object();
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add(new Object());
  }})).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add(result);
  }})).thenReturn(new PageImpl<>(new ArrayList<>()));
  assertFalse(reader.doRead() == result);
  assertEquals(result, reader.doRead());
  assertNull(reader.doRead());
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(2, pageRequest.getOffset());
  assertEquals(2, pageRequest.getPageNumber());
  assertEquals(1, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadResults() throws Exception {
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  final Object result = new Object();
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add(result);
  }}));
  assertEquals(result, 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-batch

@Test
@SuppressWarnings("serial")
public void testDoReadFirstReadSecondPage() throws Exception {
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  final Object result = new Object();
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add(new Object());
  }})).thenReturn(new PageImpl<>(new ArrayList<Object>(){{
    add(result);
  }}));
  assertFalse(reader.doRead() == result);
  assertEquals(result, reader.doRead());
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(1, pageRequest.getOffset());
  assertEquals(1, pageRequest.getPageNumber());
  assertEquals(1, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
@SuppressWarnings("serial")
public void testJumpToItem() throws Exception {
  reader.setPageSize(100);
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<Object>() {{
    add(new Object());
  }}));
  reader.jumpToItem(485);
  Pageable pageRequest = pageRequestContainer.getValue();
  assertEquals(400, pageRequest.getOffset());
  assertEquals(4, pageRequest.getPageNumber());
  assertEquals(100, pageRequest.getPageSize());
  assertEquals("id: ASC", pageRequest.getSort().toString());
}

代码示例来源:origin: spring-projects/spring-batch

@Test
public void testDifferentTypes() throws Exception {
  TestRepository differentRepository = mock(TestRepository.class);
  RepositoryItemReader<String> reader = new RepositoryItemReader<>();
  sorts = new HashMap<>();
  sorts.put("id", Direction.ASC);
  reader.setRepository(differentRepository);
  reader.setPageSize(1);
  reader.setSort(sorts);
  reader.setMethodName("findFirstNames");
  ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
  when(differentRepository.findFirstNames(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<String>(){{
    add("result");
  }}));
  assertEquals("result", 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-elasticsearch

startRecord = query.getPageable().getPageNumber() * query.getPageable().getPageSize();
sourceBuilder.size(query.getPageable().getPageSize());

代码示例来源:origin: spring-projects/spring-data-neo4j

public Pagination getPagination(Pageable pageable, boolean forSlicing) {
  Pagination pagination = new Pagination(pageable.getPageNumber(), pageable.getPageSize() + ((forSlicing) ? 1 : 0));
  pagination.setOffset(pageable.getPageNumber() * pageable.getPageSize());
  return pagination;
}

代码示例来源:origin: spring-projects/spring-data-neo4j

private String addPaging(String cypherQuery, Pageable pageable, boolean forSlicing) {
  // Custom queries in the OGM do not support pageable
  cypherQuery = formatBaseQuery(cypherQuery);
  cypherQuery = cypherQuery + SKIP_LIMIT;
  parameters.put(SKIP, pageable.getPageNumber() * pageable.getPageSize());
  if (forSlicing) {
    parameters.put(LIMIT, pageable.getPageSize() + 1);
  } else {
    parameters.put(LIMIT, pageable.getPageSize());
  }
  return cypherQuery;
}

代码示例来源:origin: spring-projects/spring-data-neo4j

@Override
  public Page<T> findAll(Pageable pageable, int depth) {
    Pagination pagination = new Pagination(pageable.getPageNumber(), pageable.getPageSize());
    Collection<T> data = session.loadAll(clazz, PagingAndSortingUtils.convert(pageable.getSort()), pagination, depth);

    return PageableExecutionUtils.getPage(new ArrayList<>(data), pageable, () -> session.countEntitiesOfType(clazz));
  }
}

代码示例来源: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: spring-projects/spring-data-rest

@Override
  public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
      NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    Pageable pageable = delegate.resolveArgument(parameter, mavContainer, webRequest, binderFactory);

    if (pageable == null || pageable.getSort() == null) {
      return new DefaultedPageable(pageable, delegate.isFallbackPageable(pageable));
    }

    Sort translated = translator.translateSort(pageable.getSort(), parameter, webRequest);
    pageable = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), translated);

    return new DefaultedPageable(pageable, delegate.isFallbackPageable(pageable));
  }
}

代码示例来源:origin: com.blazebit/blaze-persistence-integration-spring-data-base

/**
 * Construct a page request from a pageable with an optional keyset page that may be used for keyset pagination.
 *
 * @param keysetPage The keyset page
 * @param pageable   The pageable
 */
public KeysetPageRequest(KeysetPage keysetPage, Pageable pageable) {
  super(pageable.getPageNumber(), pageable.getPageSize(), pageable.getSort());
  this.keysetPage = keysetPage;
  this.offset = pageable.getPageNumber() * pageable.getPageSize();
}

代码示例来源:origin: Microsoft/spring-data-cosmosdb

@Override
  public Object execute(DocumentQuery query, Class<?> type, String collection) {
    if (pageable.getPageNumber() != 0 && !(pageable instanceof DocumentDbPageRequest)) {
      throw new IllegalStateException("Not the first page but Pageable is not a valid " +
          "DocumentDbPageRequest, requestContinuation is required for non first page request");
    }
    query.with(pageable);
    return operations.paginationQuery(query, type, collection);
  }
}

代码示例来源:origin: spring-cloud/spring-cloud-dataflow

@Override
public Page<AppStatus> getAppStatuses(Pageable pageable) {
  List<String> skipperStreams = new ArrayList<>();
  Iterable<StreamDefinition> streamDefinitions = this.streamDefinitionRepository.findAll();
  for (StreamDefinition streamDefinition : streamDefinitions) {
    skipperStreams.add(streamDefinition.getName());
  }
  List<AppStatus> allStatuses = getStreamsStatuses(skipperStreams);
  List<AppStatus> pagedStatuses = allStatuses.stream().skip(pageable.getPageNumber() * pageable.getPageSize())
      .limit(pageable.getPageSize()).parallel().collect(Collectors.toList());
  return new PageImpl<>(pagedStatuses, pageable, allStatuses.size());
}

代码示例来源:origin: nurkiewicz/spring-data-jdbc-repository

@Override
  protected String limitClause(Pageable page) {
    final int offset = page.getPageNumber() * page.getPageSize();
    return " LIMIT " + page.getPageSize() + " OFFSET " + offset;
  }
}

代码示例来源:origin: org.springframework.data/spring-data-neo4j

public Pagination getPagination(Pageable pageable, boolean forSlicing) {
  Pagination pagination = new Pagination(pageable.getPageNumber(), pageable.getPageSize() + ((forSlicing) ? 1 : 0));
  pagination.setOffset(pageable.getPageNumber() * pageable.getPageSize());
  return pagination;
}

代码示例来源:origin: org.springframework.data/spring-data-neo4j

private String addPaging(String cypherQuery, Pageable pageable, boolean forSlicing) {
  // Custom queries in the OGM do not support pageable
  cypherQuery = formatBaseQuery(cypherQuery);
  cypherQuery = cypherQuery + SKIP_LIMIT;
  parameters.put(SKIP, pageable.getPageNumber() * pageable.getPageSize());
  if (forSlicing) {
    parameters.put(LIMIT, pageable.getPageSize() + 1);
  } else {
    parameters.put(LIMIT, pageable.getPageSize());
  }
  return cypherQuery;
}

代码示例来源: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);
}

相关文章