嘿有人知道怎么能用@RequestMapping匹配这个URI“http:// localhost:8080 / test / user / 127.0.0.1:8002:8”。
我尝试编写此代码:
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET,headers="Accept=application/xml" )
public void test(@PathVariable("id") String id) {
System.out.println(id);
return null;
}
但问题是当我打印id时,值为:127.0.0 也许有些事情会发生什么?
答案 0 :(得分:12)
请参阅SpEL文档: http://static.springsource.org/spring/docs/3.0.5.RELEASE/reference/expressions.html
你会想做这样的事情:
@RequestMapping(value = "/user/{id:.*}", method = RequestMethod.GET,headers="Accept=application/xml" )
public void test(@PathVariable("id") String id) {
答案 1 :(得分:5)
如果你在Spring MVC中使用@Configuration
- 样式,那么这就可以了:
@Configuration
public class Api extends WebMvcConfigurationSupport {
@Bean
public RequestMappingHandlerMapping requestMappingHandlerMapping() {
RequestMappingHandlerMapping mapping = super.requestMappingHandlerMapping();
mapping.setUseSuffixPatternMatch(false);
return mapping;
}
}
如您所见,您必须在RequestMappingHandlerMapping
中停用useSuffixPatternMatch
。