【发布时间】:2014-10-13 19:53:25
【问题描述】:
我想使用现有的 Spring 功能从 URL 中提取路径变量和查询参数。我有一个对 MVC @RequestMapping 或 UriComponentsBuilder 有效的路径格式字符串。我也有一个实际的路径。我想从该路径中提取路径变量。
例如。
String format = "location/{state}/{city}";
String actualUrl = "location/washington/seattle";
TheThingImLookingFor parser = new TheThingImLookingFor(format);
Map<String, String> variables = parser.extractPathVariables(actualUrl);
assertThat(variables.get("state", is("washington"));
assertThat(variables.get("city", is("seattle"));
它有点像 UriComponentsBuilder 的倒数,根据我对 Javadocs 的阅读,它没有任何解析功能。
【问题讨论】:
-
能否帮助您指出正确的方向:Spring 3 RequestMapping: Get path value?
标签: java spring spring-mvc