Class WebMvcLinkBuilder

All Implemented Interfaces:
LinkBuilder

public class WebMvcLinkBuilder extends TemplateVariableAwareLinkBuilderSupport<WebMvcLinkBuilder>
Builder to ease building Link instances pointing to Spring MVC controllers.
Author:
Oliver Gierke, Kamill Sokol, Greg Turnquist, Kevin Conaway, Andrew Naydyonock, Oliver Trosien, Greg Turnquist, Lars Michele
  • Method Details

    • linkTo

      public static WebMvcLinkBuilder linkTo(Class<?> controller)
      Creates a new WebMvcLinkBuilder with a base of the mapping annotated to the given controller class.
      Parameters:
      controller - the class to discover the annotation on, must not be null.
      Returns:
    • linkTo

      public static WebMvcLinkBuilder linkTo(Class<?> controller, Object... parameters)
      Creates a new WebMvcLinkBuilder with a base of the mapping annotated to the given controller class. The additional parameters are used to fill up potentially available path variables in the class scop request mapping.
      Parameters:
      controller - the class to discover the annotation on, must not be null.
      parameters - additional parameters to bind to the URI template declared in the annotation, must not be null.
      Returns:
    • linkTo

      public static WebMvcLinkBuilder linkTo(Class<?> controller, Map<String,?> parameters)
      Creates a new WebMvcLinkBuilder with a base of the mapping annotated to the given controller class. Parameter map is used to fill up potentially available path variables in the class scope request mapping.
      Parameters:
      controller - the class to discover the annotation on, must not be null.
      parameters - additional parameters to bind to the URI template declared in the annotation, must not be null.
      Returns:
    • linkTo

      public static WebMvcLinkBuilder linkTo(Method method)
    • linkTo

      public static WebMvcLinkBuilder linkTo(Method method, Object... parameters)
    • linkTo

      public static WebMvcLinkBuilder linkTo(Class<?> controller, Method method)
    • linkTo

      public static WebMvcLinkBuilder linkTo(Class<?> controller, Method method, Object... parameters)
    • linkTo

      public static WebMvcLinkBuilder linkTo(Object invocationValue)
      Creates a WebMvcLinkBuilder pointing to a controller method. Hand in a dummy method invocation result you can create via methodOn(Class, Object...) or DummyInvocationUtils.methodOn(Class, Object...).
       @RequestMapping("/customers")
       class CustomerController {
      
         @RequestMapping("/{id}/addresses")
         HttpEntity<Addresses> showAddresses(@PathVariable Long id) { … }
       }
      
       Link link = linkTo(methodOn(CustomerController.class).showAddresses(2L)).withRel("addresses");
       
      The resulting Link instance will point to /customers/2/addresses and have a rel of addresses. For more details on the method invocation constraints, see DummyInvocationUtils.methodOn(Class, Object...).
      Parameters:
      invocationValue -
      Returns:
    • afford

      public static Affordance afford(Object invocationValue)
      Extract a Link from the WebMvcLinkBuilder and look up the related Affordance. Should only be one.
       Link findOneLink = linkTo(methodOn(EmployeeController.class).findOne(id)).withSelfRel()
                      .andAffordance(afford(methodOn(EmployeeController.class).updateEmployee(null, id)));
       
      This takes a link and adds an Affordance based on another Spring MVC handler method.
      Parameters:
      invocationValue -
      Returns:
    • methodOn

      public static <T> T methodOn(Class<T> controller, Object... parameters)
      Wrapper for DummyInvocationUtils.methodOn(Class, Object...) to be available in case you work with static imports of WebMvcLinkBuilder.
      Parameters:
      controller - must not be null.
      parameters - parameters to extend template variables in the type level mapping.
      Returns:
    • getThis

      protected WebMvcLinkBuilder getThis()
      Description copied from class: LinkBuilderSupport
      Returns the current concrete instance.
      Specified by:
      getThis in class LinkBuilderSupport<WebMvcLinkBuilder>
      Returns:
    • createNewInstance

      protected WebMvcLinkBuilder createNewInstance(org.springframework.web.util.UriComponents components, List<Affordance> affordances, TemplateVariables variables)
      Specified by:
      createNewInstance in class TemplateVariableAwareLinkBuilderSupport<WebMvcLinkBuilder>
    • toUriComponentsBuilder

      public org.springframework.web.util.UriComponentsBuilder toUriComponentsBuilder()
      Returns a UriComponentsBuilder to continue to build the already built URI in a more fine grained way.
      Returns: