Dav*_*d V 7 java spring spring-mvc
我想使用现有的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"));
Run Code Online (Sandbox Code Playgroud)
它类似于反转UriComponentsBuilder,从我对Javadocs的阅读中没有任何解析功能.
Bij*_*men 11
在这里:
String format = "location/{state}/{city}";
String actualUrl = "location/washington/seattle";
AntPathMatcher pathMatcher = new AntPathMatcher();
Map<String, String> variables = pathMatcher.extractUriTemplateVariables(format, actualUrl);
assertThat(variables.get("state"), is("washington"));
assertThat(variables.get("city"), is("seattle"));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3999 次 |
| 最近记录: |