0

我正在研究 spring。我无法在“abc.com/firstName.lastName”sping 中为这个 url 创建映射。如果我写了这段代码

@RequestMapping(value = "/{path}", method = RequestMethod.GET, produces = "application/json")
@Timed
public void saveProfileMapping(@PathVariable String path)
{
    System.out.println("-------------getting Mapping--------------"+path);
} 

然后只得到名字,即姓氏在spring.but如果这样写

@RequestMapping(value = "/{firstName}.{lastName}", method = RequestMethod.GET, produces = "application/json")
@Timed
public void saveProfileMapping(@PathVariable String firstName,String lastName)
{
    System.out.println("-------------getting Mapping--------------"+firstName+lastName);
}

同样的结果在这里只得到名字。

请需要你的帮助..

提前致谢。

4

2 回答 2

0

Marten 正确地发现了问题。另一种(更简单)的解决方案是在@RequestMapping例如这匹配所有内容中使用正则表达式:

 @RequestMapping(value = "/{path:.*}")
 public void saveProfileMapping(@PathVariable String path)
 { ... } 
于 2014-02-20T15:34:37.097 回答
0

您需要 PathVariables 的:

...
public void saveProfileMapping(@PathVariable String firstName,@PathVariable String lastName)
...

希望有帮助!

于 2014-02-20T15:37:53.733 回答