简体   繁体   中英

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

@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

@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. An alternative (easier) solution is to use a regex in the @RequestMapping eg this matches everything:

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

You need to PathVariables's:

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

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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