Template variables with ControllerLinkBuilder

后端 未结 7 2006
生来不讨喜
生来不讨喜 2021-02-13 17:54

I want my response to include this:

\"keyMaps\":{
  \"href\":\"http://localhost/api/keyMaps{/keyMapId}\",
  \"templated\":true
 }

That\'s easy

7条回答
  •  悲哀的现实
    2021-02-13 18:00

    According to this issue comment, this will be addressed in an upcoming release of spring-hateoas.

    For now, there's a drop-in replacement for ControllerLinkBuilder available from de.escalon.hypermedia:spring-hateoas-ext in Maven Central.

    I can now do this:

    import static de.escalon.hypermedia.spring.AffordanceBuilder.*
    
    ...
    
    add(linkTo(methodOn(KeyMapController.class).getKeyMap(null)).withRel("keyMaps"));
    

    I pass in null as the parameter value to indicate I want to use a template variable. The name of the variable is automatically pulled from the controller.

提交回复
热议问题