Package org.springframework.data.web
Class PagedResourcesAssembler<T>
java.lang.Object
org.springframework.data.web.PagedResourcesAssembler<T>
- All Implemented Interfaces:
- RepresentationModelAssembler<Page<T>,- PagedModel<EntityModel<T>>> 
public class PagedResourcesAssembler<T>
extends Object
implements RepresentationModelAssembler<Page<T>,PagedModel<EntityModel<T>>> 
- Since:
- 1.6
- Author:
- Oliver Gierke, Nick Williams, Marcel Overdijk
- 
Constructor SummaryConstructorsConstructorDescriptionPagedResourcesAssembler(HateoasPageableHandlerMethodArgumentResolver resolver, UriComponents baseUri) Creates a newPagedResourcesAssemblerusing the givenPageableHandlerMethodArgumentResolverand base URI.
- 
Method SummaryModifier and TypeMethodDescriptionprotected <R extends RepresentationModel<?>,S> 
 PagedModel<R>createPagedModel(List<R> resources, PagedModel.PageMetadata metadata, Page<S> page) Creates thePagedModelto be equipped with pagination links downstream.protected MethodParameterDeprecated, for removal: This API element is subject to removal in a future version.voidsetForceFirstAndLastRels(boolean forceFirstAndLastRels) PagedModel<?>toEmptyModel(Page<?> page, Class<?> type) Creates aPagedModelwith an empt collectionEmbeddedWrapperfor the given domain type.PagedModel<?>toEmptyModel(Page<?> page, Class<?> type, Link link) Creates aPagedModelwith an empt collectionEmbeddedWrapperfor the given domain type.Creates a newPagedModelby converting the givenPageinto aPagedModel.PageMetadatainstance and wrapping the contained elements intoPagedModelinstances.<R extends RepresentationModel<?>>
 PagedModel<R>toModel(Page<T> page, RepresentationModelAssembler<T, R> assembler) Creates a newPagedModelby converting the givenPageinto aPagedModel.PageMetadatainstance and using the givenPagedModelto turn elements of thePageinto resources.<R extends RepresentationModel<?>>
 PagedModel<R>Creates a newPagedModelby converting the givenPageinto aPagedModel.PageMetadatainstance and using the givenPagedModelto turn elements of thePageinto resources.withParameter(MethodParameter parameter) Creates a newPagedResourcesAssemblerwith the given referenceMethodParameter.Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.hateoas.server.RepresentationModelAssemblertoCollectionModel
- 
Constructor Details- 
PagedResourcesAssemblerpublic PagedResourcesAssembler(@Nullable HateoasPageableHandlerMethodArgumentResolver resolver, @Nullable UriComponents baseUri) Creates a newPagedResourcesAssemblerusing the givenPageableHandlerMethodArgumentResolverand 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- 
setForceFirstAndLastRelspublic void setForceFirstAndLastRels(boolean forceFirstAndLastRels) Configures whether to always addfirstandlastlinks to thePagedModelcreated. Defaults to false which means thatfirstandlastlinks only appear in conjunction withprevandnextlinks.- Parameters:
- forceFirstAndLastRels- whether to always add- firstand- lastlinks to the- PagedModelcreated.
- Since:
- 1.11
 
- 
withParameterCreates a newPagedResourcesAssemblerwith the given referenceMethodParameter.- Parameters:
- parameter- can be null.
- Returns:
- will never be null.
- Since:
- 3.1
 
- 
toModel- Specified by:
- toModelin interface- RepresentationModelAssembler<Page<T>,- PagedModel<EntityModel<T>>> 
 
- 
toModelCreates a newPagedModelby converting the givenPageinto aPagedModel.PageMetadatainstance and wrapping the contained elements intoPagedModelinstances. Will add pagination links based on the given the self link.- Parameters:
- page- must not be null.
- selfLink- must not be null.
- Returns:
 
- 
toModelpublic <R extends RepresentationModel<?>> PagedModel<R> toModel(Page<T> page, RepresentationModelAssembler<T, R> assembler) Creates a newPagedModelby converting the givenPageinto aPagedModel.PageMetadatainstance and using the givenPagedModelto turn elements of thePageinto resources.- Parameters:
- page- must not be null.
- assembler- must not be null.
- Returns:
 
- 
toModelpublic <R extends RepresentationModel<?>> PagedModel<R> toModel(Page<T> page, RepresentationModelAssembler<T, R> assembler, Link link) Creates a newPagedModelby converting the givenPageinto aPagedModel.PageMetadatainstance and using the givenPagedModelto turn elements of thePageinto 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:
 
- 
toEmptyModelCreates aPagedModelwith an empt collectionEmbeddedWrapperfor the given domain type.- Parameters:
- page- must not be null, content must be empty.
- type- must not be null.
- Returns:
- Since:
- 2.0
 
- 
toEmptyModelCreates aPagedModelwith an empt collectionEmbeddedWrapperfor 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
 
- 
createPagedModelprotected <R extends RepresentationModel<?>,S> PagedModel<R> createPagedModel(List<R> resources, PagedModel.PageMetadata metadata, Page<S> page) Creates thePagedModelto be equipped with pagination links downstream.- Parameters:
- resources- the original page's elements mapped into- RepresentationModelinstances.
- metadata- the calculated- PagedModel.PageMetadata, must not be null.
- page- the original page handed to the assembler, must not be null.
- Returns:
- must not be null.
 
- 
getMethodParameterDeprecated, for removal: This API element is subject to removal in a future version.since 3.1, rather set up the instance withwithParameter(MethodParameter).Return theMethodParameterto 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
 
 
- 
withParameter(MethodParameter).