2

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?

1 Answer 1

5

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));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.