为HTTP路径映射的不明确的处理程序方法

时间:2014-06-10 06:44:38

标签: rest spring-mvc

我有两种冲突的方法

1. @RequestMapping(value = { "/{name}" }, method = RequestMethod.GET)
    void foo1(@PathVariable("name") final String name) 

2. @RequestMapping(value = { "/{email}" }, method = RequestMethod.GET)
    void getTemplateVersionsBySenderForClient(@PathVariable("email") final String email,
            @RequestParam(value = "timestamp", required = true) final long timestamp)

我如何避免这种情况?

1 个答案:

答案 0 :(得分:-1)

您可以将URI模板更改为其他内容。您也可以更改"电子邮件"使用正则表达式的URI模板,以便第二种方法处理看起来像电子邮件地址的路径。请参阅http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/mvc.html," URI模板模式与正则表达式":

@RequestMapping("/spring-web/{symbolicName:[a-z-]+}-{version:\\d\\.\\d\\.\\d}{extension:\\.[a-z]+}")
public void handle(@PathVariable String version, @PathVariable String extension) {
  // ...
}