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 Affordanceprotected WebMvcLinkBuildercreateNewInstance(org.springframework.web.util.UriComponents components, List<Affordance> affordances, TemplateVariables variables) protected WebMvcLinkBuildergetThis()Returns the current concrete instance.static WebMvcLinkBuilderCreates a newWebMvcLinkBuilderwith a base of the mapping annotated to the given controller class.static WebMvcLinkBuilderCreates a newWebMvcLinkBuilderwith a base of the mapping annotated to the given controller class.static WebMvcLinkBuilderstatic WebMvcLinkBuilderstatic WebMvcLinkBuilderCreates a newWebMvcLinkBuilderwith a base of the mapping annotated to the given controller class.static WebMvcLinkBuilderCreates aWebMvcLinkBuilderpointing to a controller method.static WebMvcLinkBuilderstatic WebMvcLinkBuilderstatic <T> TWrapper forDummyInvocationUtils.methodOn(Class, Object...)to be available in case you work with static imports ofWebMvcLinkBuilder.org.springframework.web.util.UriComponentsBuilderReturns aUriComponentsBuilderto continue to build the already built URI in a more fine grained way.Methods inherited from class org.springframework.hateoas.server.core.TemplateVariableAwareLinkBuilderSupport
createNewInstance, toStringMethods inherited from class org.springframework.hateoas.server.core.LinkBuilderSupport
addAffordances, getAffordances, slash, slash, toUri, withRel, withSelfRelMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.hateoas.server.LinkBuilder
withRel
-
Method Details
-
linkTo
Creates a newWebMvcLinkBuilderwith 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 newWebMvcLinkBuilderwith 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 newWebMvcLinkBuilderwith 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 aWebMvcLinkBuilderpointing 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 resultingLinkinstance will point to/customers/2/addressesand have a rel ofaddresses. For more details on the method invocation constraints, seeDummyInvocationUtils.methodOn(Class, Object...).- Parameters:
invocationValue-- Returns:
-
afford
Extract aLinkfrom theWebMvcLinkBuilderand 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 anAffordancebased 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:LinkBuilderSupportReturns the current concrete instance.- Specified by:
getThisin classLinkBuilderSupport<WebMvcLinkBuilder>- Returns:
-
createNewInstance
protected WebMvcLinkBuilder createNewInstance(org.springframework.web.util.UriComponents components, List<Affordance> affordances, TemplateVariables variables) - Specified by:
createNewInstancein classTemplateVariableAwareLinkBuilderSupport<WebMvcLinkBuilder>
-
toUriComponentsBuilder
public org.springframework.web.util.UriComponentsBuilder toUriComponentsBuilder()Returns aUriComponentsBuilderto continue to build the already built URI in a more fine grained way.- Returns:
-