Skip to content

Pagination

Christian KASSE edited this page Apr 2, 2026 · 1 revision

Pagination

Overview

All list endpoints in the SDK return paginated results using PageRequest and PageResponse.

PageRequest

Build a page request with the builder:

import com.essabu.common.model.PageRequest;

PageRequest page = PageRequest.builder()
    .page(0)                    // Page number (0-based)
    .size(25)                   // Items per page (default: 20, max: 100)
    .sort("createdAt,desc")     // Sort field and direction
    .build();

Parameters

Parameter Type Default Description
page int 0 Zero-based page index
size int 20 Number of items per page (max 100)
sort String null Sort expression: field,asc or field,desc

PageResponse

The response contains the data and pagination metadata:

import com.essabu.common.model.PageResponse;

PageResponse<Map> result = essabu.hr().employees().list(companyId, page);

// Access data
List<Map> items = result.getContent();

// Pagination metadata
int totalElements = result.getTotalElements();
int totalPages = result.getTotalPages();
int currentPage = result.getNumber();
int pageSize = result.getSize();
boolean isFirst = result.isFirst();
boolean isLast = result.isLast();
boolean hasNext = result.hasNext();
boolean hasPrevious = result.hasPrevious();

PageResponse Fields

Field Type Description
content List<T> Items on the current page
totalElements int Total number of items across all pages
totalPages int Total number of pages
number int Current page number (0-based)
size int Page size
first boolean Whether this is the first page
last boolean Whether this is the last page

Iterating All Pages

int page = 0;
PageResponse<Map> result;
do {
    result = essabu.hr().employees().list(
        companyId,
        PageRequest.builder().page(page).size(50).build()
    );
    for (Map employee : result.getContent()) {
        processEmployee(employee);
    }
    page++;
} while (result.hasNext());

Sorting

Sort by any field in ascending or descending order:

// Sort by last name ascending
PageRequest.builder().sort("lastName,asc").build();

// Sort by creation date descending
PageRequest.builder().sort("createdAt,desc").build();

Filtering

Some list endpoints accept additional filter parameters as part of the request:

// Endpoints that accept companyId as a parameter
essabu.hr().employees().list(companyId, pageRequest);

// Endpoints with query parameters
essabu.accounting().wallets().listTransactions(walletId, pageRequest);

Clone this wiki locally