I have a method with a request parameter and I'm trying to link to this method from another resource. I want the link to be something like this:
"rel":{
"href":".../resources{?param}",
"templated":true
}
I tried the following without success:
//First attempt
resources.add(linkTo(methodOn(Controller.class).method(null)).withRel("rel")
//Second attempt
resources.add(linkTo(methodOn(Controller.class).method("{parameter}")).withRel("rel")
//Third attempt
resources.add(entityLinks.linkToCollectionResource(LinkedResource.class).withRel("rel");
It does work now, you can check the following issue which has been resolved now - https://github.com/spring-projects/spring-hateoas/issues/169.
As you have mentioned above in your first attempt -
resources.add(linkTo(methodOn(Controller.class).method(null)).withRel("rel")
should work.
This isn't currently a part of spring-hateoas
, see this open bug report, which suggests adding this functionality to ControllerLinkBuilder
and this previous question which has an answer with a custom implementation for doing this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With