1

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?

Mak
  • 205
  • 1
  • 4
  • 8

1 Answers1

4

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));
MaVVamaldo
  • 2,505
  • 7
  • 28
  • 50