Question

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 i.e 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.

Was it helpful?

Solution

You need to PathVariables's:

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

Hope that helps!

OTHER TIPS

Marten identified the problem correctly. An alternative (easier) solution is to use a regex in the @RequestMapping e.g. this matches everything:

 @RequestMapping(value = "/{path:.*}")
 public void saveProfileMapping(@PathVariable String path)
 { ... } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top