Extends pagination-pageable-sample with DTO mapping.
The repository returns domain objects — Customer.
The application layer converts the result into view objects — CustomerView — without rebuilding pagination metadata.
The key idea: PageResult.map() transforms the content across layers while preserving page number, size and total count unchanged.
All code is in a single file: PaginationDtoMapping.java
PaginationDtoMapping.java
│
├── Customer # Domain model — record with id and name
├── CustomerView # DTO — read model for the application layer
├── CustomerMapper # Maps Customer → CustomerView
├── PageRequest # Pagination request — page number and size
├── PageResult<T> # Pagination result — content + metadata + map()
├── CustomerRepository # Data access — returns PageResult<Customer>
├── FakeCustomerTable # In-memory data source — simulates a database table
└── PaginationDtoMapping # Entry point + demo()
PageResult.map() preserves metadata. Converts the content type without touching page number, size or total — no manual reconstruction needed.
Each layer owns its transformation. The repository returns PageResult<Customer>. The application layer maps it to PageResult<CustomerView> in a single call.
CustomerMapper holds the mapping logic. Domain objects and view objects stay clean with no cross-layer constructors.
PageResult[content=[CustomerView[id=1, name=Alice], CustomerView[id=2, name=Bob]], page=0, size=2, total=5]
The repository returned Customer records. The application layer received CustomerView records. Pagination metadata passed through unchanged.
./mvnw spring-boot:run- Previous: pagination-pageable-sample
- Next: pagination-sorting-sample