Exemplo n.º 1
0
  public WebPageDto(Page<T> page, String url) {
    this.url = url;
    this.totalPages = page.getTotalPages();
    this.totalElements = page.getTotalElements();
    this.firstPage = page.isFirstPage();
    this.lastPage = page.isLastPage();
    this.hasPreviousPage = page.hasPreviousPage();
    this.hasNextPage = page.hasNextPage();
    this.size = page.getSize();
    this.number = page.getNumber() + 1;
    this.content = page.getContent();

    int start, size;
    if (totalPages <= DEFAULT_PAGES) {
      start = 1;
      size = totalPages;
    } else {
      if (number <= DEFAULT_PAGES - DEFAULT_PAGES / 2) {
        start = 1;
        size = DEFAULT_PAGES;
      } else if (number >= totalPages - DEFAULT_PAGES / 2) {
        start = totalPages - DEFAULT_PAGES + 1;
        size = DEFAULT_PAGES;
      } else {
        start = number - DEFAULT_PAGES / 2;
        size = DEFAULT_PAGES;
      }
    }

    for (int i = 0; i < size; i++) {
      items.add(new PageItem(start + i, (start + i) == number));
    }
  }
  /**
   * Add all bean properties from the supplied bean to the representation
   *
   * @param value
   * @return
   */
  public ResponseEntityBuilder<ReadableRepresentation> withPage(
      Page<?> value, String uriTemplate, String... includeFields) {
    String[] fields = requestedFields == null ? includeFields : requestedFields;

    // Extract page data such as size, page number
    representation.withProperty("size", value.getSize());
    representation.withProperty("number", value.getNumber());
    representation.withProperty("numberOfElements", value.getNumberOfElements());
    representation.withProperty("totalElements", value.getTotalElements());

    // Next/back links
    if (value.hasNextPage()) {
      buildNextLink(representation, request);
    }
    if (value.hasPreviousPage()) {
      buildPreviousLink(representation, request);
    }

    // Build the content of the page
    for (Object object : value.getContent()) {
      Representation content = converter.convert(object, new UriTemplate(uriTemplate), fields);
      this.representation.withRepresentation("content", content);
    }
    return this;
  }
  @Test
  public void findsFirstPageOfMatthews() throws Exception {

    Page<Customer> customers = repository.findByLastname("Matthews", new PageRequest(0, 2));

    assertThat(customers.getContent().size(), is(2));
    assertFalse(customers.hasPreviousPage());
  }
Exemplo n.º 4
0
 private WebPage(Page<T> page) {
   number = page.getNumber();
   size = page.getSize();
   totalPages = page.getTotalPages();
   numberOfElements = page.getNumberOfElements();
   totalElements = page.getTotalElements();
   hasPreviousPage = page.hasPreviousPage();
   isFirstPage = page.isFirstPage();
   hasNextPage = page.hasNextPage();
   isLastPage = page.isLastPage();
   content = page.getContent();
   hasContent = page.hasContent();
   sort = new WebSort(page.getSort());
 }
Exemplo n.º 5
0
  @RequiresPermissions("role:view")
  @RequestMapping(value = "")
  public String list(PageRequest pageRequest, Model model, ServletRequest request) {

    if (StringUtils.isBlank(pageRequest.getOrderBy())) {
      pageRequest.setOrderBy("id");
      pageRequest.setOrderDir("desc");
    }

    Page<Role> roles =
        roleServcie.search(Servlets.getParametersStartingWith(request, "search_"), pageRequest);
    pageRequest.setPrePage(roles.hasPreviousPage());
    pageRequest.setNextPage(roles.hasNextPage());

    model.addAttribute("page", roles);
    model.addAttribute("pageRequest", pageRequest);
    return "account/role/roleList";
  }