Template variables with ControllerLinkBuilder

后端 未结 7 2023
生来不讨喜
生来不讨喜 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:11

    With latest versions of spring-hateoas you can do the following:

    UriComponents uriComponents = UriComponentsBuilder.fromUri(linkBuilder.toUri()).build();
    UriTemplate template = new UriTemplate(uriComponents.toUriString())
       .with("keyMapId", TemplateVariable.SEGMENT);
    

    will give you: http://localhost:8080/bla{/keyMapId}",

提交回复
热议问题