简体   繁体   English

无法创建Spring Url映射

[英]Unable to Create Spring Url mapping

I am working on spring.I am unable to create mapping for this url in "abc.com/firstName.lastName" sping.if i have write this code 我正在使用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);
} 

Then get only firstname ie lastname is not get in spring.but if write like that 然后仅获取名字,即姓氏不会在spring中获取。但是如果这样写

@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);
}

Same result here get only firstname. 同样的结果在这里只获得名字。

Please need your help.. 请您帮忙。

Thanks in advance. 提前致谢。

Marten identified the problem correctly. Marten正确识别了问题。 An alternative (easier) solution is to use a regex in the @RequestMapping eg this matches everything: 另一种(更简便的)解决方案是在@RequestMapping使用正则表达式,例如,它匹配所有内容:

 @RequestMapping(value = "/{path:.*}")
 public void saveProfileMapping(@PathVariable String path)
 { ... } 

You need to PathVariables's: 您需要使用PathVariables:

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

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM