2013-10-17 50 views

回答

1

解析URI模板涉及两个类。

  • AntPathMatcher.extractUriTemplateVariables():用于@RequestMapping MVC注释
  • UriTemplate:用于RestTemplate客户端。

您可以使用这些类来测试URI模板的解析方式。

例如,对于MVC RequestMapping:

1

Spring不支持RFC6570,

例如,第一道次和第二失败。

@Test 
public void thatUriPathVariablesWithSlashGetEncoded() { 
    String uri = com.damnhandy.uri.template.UriTemplate.fromTemplate("http://localhost:80/context/entity/{var1}/{var2}").set("var1", "my/Id").set("var2", "blah").expand(); 

    Assert.assertThat(uri, Matchers.is("http://localhost:80/context/entity/my%2FId/blah")); 
} 

@Test 
public void thatUriPathVariablesWithSlashGetEncodedWithSpring() { 
    String uri = new org.springframework.web.util.UriTemplate("http://localhost:80/context/entity/{var1}/{var2}").expand("my/Id", "blah") 
      .toASCIIString(); 

    Assert.assertThat(uri, Matchers.is("http://localhost:80/context/entity/my%2FId/blah")); 
} 

有一张票可以增加支持一天。 https://jira.spring.io/browse/SPR-10505