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>>>
RepresentationModelAssembler to easily convert Page instances into PagedModel.
Since:
1.6
Author:
Oliver Gierke, Nick Williams, Marcel Overdijk
  • Constructor Summary

    Constructors
    Constructor
    Description
    PagedResourcesAssembler(HateoasPageableHandlerMethodArgumentResolver resolver, org.springframework.web.util.UriComponents baseUri)
    Creates a new PagedResourcesAssembler using the given PageableHandlerMethodArgumentResolver and base URI.
  • Method Summary

    Modifier and Type
    Method
    Description
    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 the PagedModel to be equipped with pagination links downstream.
    protected org.springframework.core.MethodParameter
    Deprecated, for removal: This API element is subject to removal in a future version.
    since 3.1, rather set up the instance with withParameter(MethodParameter).
    void
    setForceFirstAndLastRels(boolean forceFirstAndLastRels)
    Configures whether to always add first and last links to the PagedModel created.
    org.springframework.hateoas.PagedModel<?>
    toEmptyModel(Page<?> page, Class<?> type)
    Creates a PagedModel with an empt collection EmbeddedWrapper for the given domain type.
    org.springframework.hateoas.PagedModel<?>
    toEmptyModel(Page<?> page, Class<?> type, org.springframework.hateoas.Link link)
    Creates a PagedModel with an empt collection EmbeddedWrapper for the given domain type.
    org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>>
    toModel(Page<T> entity)
     
    org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>>
    toModel(Page<T> page, org.springframework.hateoas.Link selfLink)
    Creates a new PagedModel by converting the given Page into a PagedModel.PageMetadata instance and wrapping the contained elements into PagedModel instances.
    <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 new PagedModel by converting the given Page into a PagedModel.PageMetadata instance and using the given PagedModel to turn elements of the Page into resources.
    <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 new PagedModel by converting the given Page into a PagedModel.PageMetadata instance and using the given PagedModel to turn elements of the Page into resources.
    withParameter(org.springframework.core.MethodParameter parameter)
    Creates a new PagedResourcesAssembler with the given reference MethodParameter.

    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

  • Method Details

    • setForceFirstAndLastRels

      public void setForceFirstAndLastRels(boolean forceFirstAndLastRels)
      Configures whether to always add first and last links to the PagedModel created. Defaults to false which means that first and last links only appear in conjunction with prev and next links.
      Parameters:
      forceFirstAndLastRels - whether to always add first and last links to the PagedModel created.
      Since:
      1.11
    • withParameter

      public PagedResourcesAssembler<T> withParameter(@Nullable org.springframework.core.MethodParameter parameter)
      Creates a new PagedResourcesAssembler with the given reference MethodParameter.
      Parameters:
      parameter - can be null.
      Returns:
      will never be null.
      Since:
      3.1
    • toModel

      public org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>> toModel(Page<T> entity)
      Specified by:
      toModel in interface org.springframework.hateoas.server.RepresentationModelAssembler<Page<T>,org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>>>
    • toModel

      public org.springframework.hateoas.PagedModel<org.springframework.hateoas.EntityModel<T>> toModel(Page<T> page, org.springframework.hateoas.Link selfLink)
      Creates a new PagedModel by converting the given Page into a PagedModel.PageMetadata instance and wrapping the contained elements into PagedModel 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 new PagedModel by converting the given Page into a PagedModel.PageMetadata instance and using the given PagedModel to turn elements of the Page 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 new PagedModel by converting the given Page into a PagedModel.PageMetadata instance and using the given PagedModel to turn elements of the Page 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

      public org.springframework.hateoas.PagedModel<?> toEmptyModel(Page<?> page, Class<?> type)
      Creates a PagedModel with an empt collection EmbeddedWrapper 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 a PagedModel with an empt collection EmbeddedWrapper 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 the PagedModel to be equipped with pagination links downstream.
      Parameters:
      resources - the original page's elements mapped into RepresentationModel instances.
      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.
    • getMethodParameter

      @Nullable @Deprecated(since="3.1", forRemoval=true) protected org.springframework.core.MethodParameter getMethodParameter()
      Deprecated, for removal: This API element is subject to removal in a future version.
      since 3.1, rather set up the instance with withParameter(MethodParameter).
      Return the MethodParameter 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