Paging

Paging is the standard request-side pagination params class.

Bind it with @RequestBean Paging and it captures the page/size/order query parameters, then converts to a Micronaut Pageable on demand.

Query parameters

Parameter Default Notes

page

0

Zero-based page index. Clamped to 0 when negative.

size

25

Page size, defaulting to Paging.DEFAULT_PAGE_SIZE (25). Capped at Paging.MAX_PAGE_SIZE (200).

orderByField

none

Field to order by. Validate it against an allow-list — see Query-param smuggle-rejection.

orderByDirection

DESC

ASC or DESC. Applied only when orderByField is set.

Converting to a Pageable

toPageable() clamps page and size and applies ordering only when orderByField is set:

Pageable pageable = paging.toPageable();

toPageableWithDefaults(field, direction) supplies a default order, but only when the client did not request one:

Pageable pageable = paging.toPageableWithDefaults("createdAt", Direction.DESC);

Producing a paginated envelope

Envelopes.slice(…​) turns a Micronaut Page or Slice into a SliceEnvelope, setting content, pageNumber, and pageSize:

var page = service.find(query, paging.toPageable());

return Envelopes.slice(page, tenantId);

pageNumber is zero-based, mirroring Micronaut’s Page/Slice serialization.