How to build a templated link?

廉价感情. 提交于 2019-12-10 14:17:35

问题


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");

回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/29218817/how-to-build-a-templated-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!