Class WebMvcLinkBuilder
java.lang.Object
org.springframework.hateoas.server.core.LinkBuilderSupport<T>
org.springframework.hateoas.server.core.TemplateVariableAwareLinkBuilderSupport<WebMvcLinkBuilder>
org.springframework.hateoas.server.mvc.WebMvcLinkBuilder
- All Implemented Interfaces:
LinkBuilder
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 Summary
Modifier and TypeMethodDescriptionstatic Affordance
protected WebMvcLinkBuilder
createNewInstance
(UriComponents components, List<Affordance> affordances, TemplateVariables variables) protected WebMvcLinkBuilder
getThis()
Returns the current concrete instance.static WebMvcLinkBuilder
Creates a newWebMvcLinkBuilder
with a base of the mapping annotated to the given controller class.static WebMvcLinkBuilder
Creates a newWebMvcLinkBuilder
with a base of the mapping annotated to the given controller class.static WebMvcLinkBuilder
static WebMvcLinkBuilder
static WebMvcLinkBuilder
Creates a newWebMvcLinkBuilder
with a base of the mapping annotated to the given controller class.static WebMvcLinkBuilder
Creates aWebMvcLinkBuilder
pointing to a controller method.static WebMvcLinkBuilder
static WebMvcLinkBuilder
static <T> T
Wrapper forDummyInvocationUtils.methodOn(Class, Object...)
to be available in case you work with static imports ofWebMvcLinkBuilder
.Returns aUriComponentsBuilder
to continue to build the already built URI in a more fine grained way.Methods inherited from class org.springframework.hateoas.server.core.TemplateVariableAwareLinkBuilderSupport
createNewInstance, toString
Methods inherited from class org.springframework.hateoas.server.core.LinkBuilderSupport
addAffordances, getAffordances, slash, slash, toUri, withRel, withSelfRel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.hateoas.server.LinkBuilder
withRel
-
Method Details
-
linkTo
Creates a newWebMvcLinkBuilder
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
Creates a newWebMvcLinkBuilder
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
Creates a newWebMvcLinkBuilder
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
-
linkTo
-
linkTo
-
linkTo
-
linkTo
Creates aWebMvcLinkBuilder
pointing to a controller method. Hand in a dummy method invocation result you can create viamethodOn(Class, Object...)
orDummyInvocationUtils.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 resultingLink
instance will point to/customers/2/addresses
and have a rel ofaddresses
. For more details on the method invocation constraints, seeDummyInvocationUtils.methodOn(Class, Object...)
.- Parameters:
invocationValue
-- Returns:
-
afford
Extract aLink
from theWebMvcLinkBuilder
and look up the relatedAffordance
. 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 anAffordance
based on another Spring MVC handler method.- Parameters:
invocationValue
-- Returns:
-
methodOn
Wrapper forDummyInvocationUtils.methodOn(Class, Object...)
to be available in case you work with static imports ofWebMvcLinkBuilder
.- Parameters:
controller
- must not be null.parameters
- parameters to extend template variables in the type level mapping.- Returns:
-
getThis
Description copied from class:LinkBuilderSupport
Returns the current concrete instance.- Specified by:
getThis
in classLinkBuilderSupport<WebMvcLinkBuilder>
- Returns:
-
createNewInstance
protected WebMvcLinkBuilder createNewInstance(UriComponents components, List<Affordance> affordances, TemplateVariables variables) - Specified by:
createNewInstance
in classTemplateVariableAwareLinkBuilderSupport<WebMvcLinkBuilder>
-
toUriComponentsBuilder
Returns aUriComponentsBuilder
to continue to build the already built URI in a more fine grained way.- Returns:
-