Template variables with ControllerLinkBuilder

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

    Starting with this commit:

    https://github.com/spring-projects/spring-hateoas/commit/2daf8aabfb78b6767bf27ac3e473832c872302c7

    You can now pass null where path variable is expected. It works for me, without workarounds.

    resource.add(linkTo(methodOn(UsersController.class).someMethod(null)).withRel("someMethod"));
    

    And the result:

        "someMethod": {
            "href": "http://localhost:8080/api/v1/users/{userId}",
            "templated": true
        },
    

    Also check related issues: https://github.com/spring-projects/spring-hateoas/issues/545

提交回复
热议问题