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 に答える