Reputation: 215
I have a url path pattern in SpringMVC which looks like:
/person/{personId}/address/{addressId}
and I have personId = 2 and addressId = 3 Is there an easy way for me to generate
/person/2/address/3
using a utility method within SpringMvc?
Upvotes: 2
Views: 1693
Reputation: 2535
look at UriTemplate class. you can construct your own UriTemplate from your URL, and then expand the template variables.
UriTemplate template = new UriTemplate("http://example.com/hotels/{hotel}/bookings/{booking}");
Map<String, String> uriVariables = new HashMap<String, String>();
uriVariables.put("booking", "42");
uriVariables.put("hotel", "1");
System.out.println(template.expand(uriVariables));
Upvotes: 5