Package org.springframework.data.web
Class PagedResourcesAssembler<T>
java.lang.Object
org.springframework.data.web.PagedResourcesAssembler<T>
- All Implemented Interfaces:
org.springframework.hateoas.server.RepresentationModelAssembler<Page<T>,
org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>>>
public class PagedResourcesAssembler<T>
extends Object
implements org.springframework.hateoas.server.RepresentationModelAssembler<Page<T>,org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>>>
- Since:
- 1.6
- Author:
- Oliver Gierke, Nick Williams, Marcel Overdijk
-
Constructor Summary
ConstructorDescriptionPagedResourcesAssembler
(HateoasPageableHandlerMethodArgumentResolver resolver, UriComponents baseUri) Creates a newPagedResourcesAssembler
using the givenPageableHandlerMethodArgumentResolver
and base URI. -
Method Summary
Modifier and TypeMethodDescriptionprotected <R extends org.springframework.hateoas.RepresentationModel<?>,
S>
org.springframework.hateoas.PagedModel<R>createPagedModel
(List<R> resources, org.springframework.hateoas.PagedModel.PageMetadata metadata, Page<S> page) Creates thePagedModel
to be equipped with pagination links downstream.protected MethodParameter
Return theMethodParameter
to be used to potentially qualify the paging and sorting request parameters to.void
setForceFirstAndLastRels
(boolean forceFirstAndLastRels) Configures whether to always addfirst
andlast
links to thePagedModel
created.org.springframework.hateoas.PagedModel<?>
toEmptyModel
(Page<?> page, Class<?> type) Creates aPagedModel
with an empt collectionEmbeddedWrapper
for the given domain type.org.springframework.hateoas.PagedModel<?>
toEmptyModel
(Page<?> page, Class<?> type, org.springframework.hateoas.Link link) Creates aPagedModel
with an empt collectionEmbeddedWrapper
for the given domain type.org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>>
org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>>
Creates a newPagedModel
by converting the givenPage
into aPagedModel.PageMetadata
instance and wrapping the contained elements intoPagedModel
instances.<R extends org.springframework.hateoas.RepresentationModel<?>>
org.springframework.hateoas.PagedModel<R>toModel
(Page<T> page, org.springframework.hateoas.server.RepresentationModelAssembler<T, R> assembler) <R extends org.springframework.hateoas.RepresentationModel<?>>
org.springframework.hateoas.PagedModel<R>Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.hateoas.server.RepresentationModelAssembler
toCollectionModel
-
Constructor Details
-
PagedResourcesAssembler
public PagedResourcesAssembler(@Nullable HateoasPageableHandlerMethodArgumentResolver resolver, @Nullable UriComponents baseUri) Creates a newPagedResourcesAssembler
using the givenPageableHandlerMethodArgumentResolver
and base URI. If the former is null, a default one will be created. If the latter is null, calls totoModel(Page)
will use the current request's URI to build the relevant previous and next links.- Parameters:
resolver
- can be null.baseUri
- can be null.
-
-
Method Details
-
setForceFirstAndLastRels
public void setForceFirstAndLastRels(boolean forceFirstAndLastRels) Configures whether to always addfirst
andlast
links to thePagedModel
created. Defaults to false which means thatfirst
andlast
links only appear in conjunction withprev
andnext
links.- Parameters:
forceFirstAndLastRels
- whether to always addfirst
andlast
links to thePagedModel
created.- Since:
- 1.11
-
toModel
-
toModel
public org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>> toModel(Page<T> page, org.springframework.hateoas.Link selfLink) Creates a newPagedModel
by converting the givenPage
into aPagedModel.PageMetadata
instance and wrapping the contained elements intoPagedModel
instances. Will add pagination links based on the given the self link.- Parameters:
page
- must not be null.selfLink
- must not be null.- Returns:
-
toModel
public <R extends org.springframework.hateoas.RepresentationModel<?>> org.springframework.hateoas.PagedModel<R> toModel(Page<T> page, org.springframework.hateoas.server.RepresentationModelAssembler<T, R> assembler) Creates a newPagedModel
by converting the givenPage
into aPagedModel.PageMetadata
instance and using the givenPagedModel
to turn elements of thePage
into resources.- Parameters:
page
- must not be null.assembler
- must not be null.- Returns:
-
toModel
public <R extends org.springframework.hateoas.RepresentationModel<?>> org.springframework.hateoas.PagedModel<R> toModel(Page<T> page, org.springframework.hateoas.server.RepresentationModelAssembler<T, R> assembler, org.springframework.hateoas.Link link) Creates a newPagedModel
by converting the givenPage
into aPagedModel.PageMetadata
instance and using the givenPagedModel
to turn elements of thePage
into resources. Will add pagination links based on the given the self link.- Parameters:
page
- must not be null.assembler
- must not be null.link
- must not be null.- Returns:
-
toEmptyModel
Creates aPagedModel
with an empt collectionEmbeddedWrapper
for the given domain type.- Parameters:
page
- must not be null, content must be empty.type
- must not be null.- Returns:
- Since:
- 2.0
-
toEmptyModel
public org.springframework.hateoas.PagedModel<?> toEmptyModel(Page<?> page, Class<?> type, org.springframework.hateoas.Link link) Creates aPagedModel
with an empt collectionEmbeddedWrapper
for the given domain type.- Parameters:
page
- must not be null, content must be empty.type
- must not be null.link
- must not be null.- Returns:
- Since:
- 1.11
-
createPagedModel
protected <R extends org.springframework.hateoas.RepresentationModel<?>,S> org.springframework.hateoas.PagedModel<R> createPagedModel(List<R> resources, org.springframework.hateoas.PagedModel.PageMetadata metadata, Page<S> page) Creates thePagedModel
to be equipped with pagination links downstream.- Parameters:
resources
- the original page's elements mapped intoRepresentationModel
instances.metadata
- the calculatedPagedModel.PageMetadata
, must not be null.page
- the original page handed to the assembler, must not be null.- Returns:
- must not be null.
-
getMethodParameter
Return theMethodParameter
to be used to potentially qualify the paging and sorting request parameters to. Default implementations returns null, which means the parameters will not be qualified.- Returns:
- Since:
- 1.7
-