java - How to add query string parameters with Spring HATEOAS? -
i'm trying generate link search resources. so, want create resource provides link search:
post /resourcesearch {param1: "value1",param2:"value2"}
the response should be:
{"links":[ { "rel":"self", "href":"http://localhost:8080/resourcesearch" }, { "rel":"resources", "href":"http://localhost:8080/resources?param1=value1¶m2=value2" } }
here code:
@controller @requestmapping("/resourcesearch") public class resourcesearchcontroller{ @requestmapping(method = requestmethod.post) public responseentity<resourcesupport> createresourcesearch(@requestbody resourcedto dto){ resourcesupport resource = new resourcesupport(); //... here build query string based on "dto" resource.add(linkto(resourcecontroller.class).withrel("resources")); return new responseentity<resourcesupport>(resource, httpstatus.created); } } =========================================== @controller @requestmapping("/resources") public class resourcecontroller{ @requestmapping(method = requestmethod.get) public responseentity<collectiondto> listresources(@requestparam("param1") string param1, @requestparam("param2") string param2){ ... } }
the thing can't figure out how add query string parameters url in line:
resource.add(linkto(resourcecontroller.class).withrel("resources"));
because result of line is:
{ "links" : [ { "rel":"resources", "href":"http://localhost:8080/resources" } ] }
any ideas?
there couple of (potential) mismatches between names have used in resources , desired output, hence not able map well.
anyway, need use methodon
of controllerlinkbuilder
. here's example should going.
Comments
Post a Comment