Klasse SpringControllerLinkBuilder
java.lang.Object
de.kamillionlabs.hateoflux.linkbuilder.SpringControllerLinkBuilder
Provides functionality to build URI links pointing to Spring controllers. It is designed to work seamlessly with
various Spring annotations such as
RestController, GetMapping, PathVariable,
RequestParam, etc. This class aims to be a direct replacement for the WebMvcLinkBuilder i.e.
WebFluxLinkBuilder in Spring HATEOAS, offering a similar interface and usage.-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungstatic <ControllerT>
LinkVariation of thelinkTo(Class, ControllerMethodReference)method.static <ControllerT>
LinklinkTo(Class<ControllerT> controllerClass, ControllerMethodReference<ControllerT> methodRef) Creates aLinkobject that represents a link to the resource(s) addressed by calling the API of the specified controller class.
-
Methodendetails
-
linkTo
public static <ControllerT> Link linkTo(Class<ControllerT> controllerClass, ControllerMethodReference<ControllerT> methodRef) Creates aLinkobject that represents a link to the resource(s) addressed by calling the API of the specified controller class. This method uses theControllerMethodReferenceto ensure type-safe referencing of controller methods. The link is expanded using the parameters in the template and the parameters with which the method reference was called.The method distinguishes between
PathVariableandRequestParam(i.e., query parameters). When parameters of the latter type are used, collections are allowed. By default, collections are expanded in a non-composite way (i.e.,var=1,2as opposed tovar=1&var=2). If the parameter in the controller class is annotated withComposite, thenlinkTo()will adhere to it, i.e., render it in the composite way.Example usage:
@ signs are prepended with "_" because of a javadocs bug where the @ the beginning of a line is interpreted and thus messes up the code exampleGiven the following class:
_@Controller; _@RequestMapping("/user") public class UserController { _@GetMapping("/{userId}") public User getUser(@PathVariable userId){ ... } }When the
linkTo()method is called as follows:Link link = linkTo(UserController.class, c -> c.getUser("12345"));The resulting link has then the href:
/user/12345- Typparameter:
ControllerT- the type of the controller- Parameter:
controllerClass- the class of the controller containing the target method. This class must be annotated withRestControllerorControllerto be valid.methodRef- a functional interface implementation that references the controller method for which the link is to be generated.- Gibt zurück:
- an expanded
Linkobject that encapsulates the URI pointing to the resource as exposed by the controller method referenced - Löst aus:
IllegalArgumentException- if the controller class is not correctly annotated as aControllerorRestController, which is necessary for the correct functioning of the method reference.
-
linkTo
Variation of thelinkTo(Class, ControllerMethodReference)method. Please refer to the mentioned method for full documentation and usage examples. This method calls the aforementioned method withmethodRef=null.- Typparameter:
ControllerT- the type of the controller- Parameter:
controllerClass- the class of the controller containing the target method. This class must be annotated withRestControllerorControllerto be valid.- Gibt zurück:
- a
Linkobject that encapsulates the URI pointing to the resource as exposed by the controller method referenced
-