1

我在 SpringMVC 中有一个 url 路径模式,如下所示:

/person/{personId}/address/{addressId}

我有 personId = 2 和 addressId = 3 有没有一种简单的方法可以生成

/person/2/address/3 

在 SpringMvc 中使用实用程序方法?

4

1 回答 1

4

看看UriTemplate类。您可以从您的 URL 构建您自己的 UriTemplate,然后展开模板变量。

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));
于 2016-02-22T14:07:06.213 回答