當前位置: 首頁>>代碼示例>>Java>>正文


Java Page.hasPrevious方法代碼示例

本文整理匯總了Java中org.springframework.data.domain.Page.hasPrevious方法的典型用法代碼示例。如果您正苦於以下問題:Java Page.hasPrevious方法的具體用法?Java Page.hasPrevious怎麽用?Java Page.hasPrevious使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.data.domain.Page的用法示例。


在下文中一共展示了Page.hasPrevious方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addPaginationData

import org.springframework.data.domain.Page; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public HttpHeaders addPaginationData(HttpHeaders headers, Page<?> page) {
	addHeaderAndLog(headers, ApiHttpHeaders.TOTAL_COUNT, this.totalCountHeaderBuilder.buildTotal(page));

	if (!page.isFirst()) {
		addHeaderAndLog(headers, ApiHttpHeaders.LINK, this.linkHeaderBuilder.buildFirst());
	}

	if (!page.isLast()) {
		addHeaderAndLog(headers, ApiHttpHeaders.LINK, this.linkHeaderBuilder.buildLast(page));
	}

	if (page.hasPrevious()) {
		addHeaderAndLog(headers, ApiHttpHeaders.LINK, this.linkHeaderBuilder.buildPrev(page));
	}

	if (page.hasNext()) {
		addHeaderAndLog(headers, ApiHttpHeaders.LINK, this.linkHeaderBuilder.buildNext(page));
	}

	return headers;
}
 
開發者ID:cmateosl,項目名稱:role-api,代碼行數:26,代碼來源:HateoasPaginationHeadersBuilder.java

示例2: getAllBooks

import org.springframework.data.domain.Page; //導入方法依賴的package包/類
@GetMapping
public ResponseEntity<List<Book>> getAllBooks(
        @PageableDefault(size = MAX_PAGE_SIZE) Pageable pageable,
        @RequestParam(required = false, defaultValue = "id") String sort,
        @RequestParam(required = false, defaultValue = "asc") String order) {
    final PageRequest pr = PageRequest.of(
            pageable.getPageNumber(), pageable.getPageSize(),
            Sort.by("asc" .equals(order) ? Sort.Direction.ASC : Sort.Direction.DESC, sort)
    );

    Page<Book> booksPage = bookRepository.findAll(pr);

    if (booksPage.getContent().isEmpty()) {
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    } else {
        long totalBooks = booksPage.getTotalElements();
        int nbPageBooks = booksPage.getNumberOfElements();

        HttpHeaders headers = new HttpHeaders();
        headers.add("X-Total-Count", String.valueOf(totalBooks));

        if (nbPageBooks < totalBooks) {
            headers.add("first", buildPageUri(PageRequest.of(0, booksPage.getSize())));
            headers.add("last", buildPageUri(PageRequest.of(booksPage.getTotalPages() - 1, booksPage.getSize())));

            if (booksPage.hasNext()) {
                headers.add("next", buildPageUri(booksPage.nextPageable()));
            }

            if (booksPage.hasPrevious()) {
                headers.add("prev", buildPageUri(booksPage.previousPageable()));
            }

            return new ResponseEntity<>(booksPage.getContent(), headers, HttpStatus.PARTIAL_CONTENT);
        } else {
            return new ResponseEntity(booksPage.getContent(), headers, HttpStatus.OK);
        }
    }
}
 
開發者ID:sbouclier,項目名稱:java-rest-books,代碼行數:40,代碼來源:BookController.java


注:本文中的org.springframework.data.domain.Page.hasPrevious方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。