Reputation: 731
I am using spring-boot 1.4.3.RELEASE for creating web services, whereas, while giving the request with http://localhost:7211/person/get/ram
, I am getting null for the id property
@RequestMapping(value="/person/get/{id}", method=RequestMethod.GET, produces="application/json")
public @ResponseBody Person getPersonById(@PathParam("id") String id) {
return personService.getPersonById(id);
}
Can you please suggest me, is there anything I missed.
Upvotes: 26
Views: 49674
Reputation: 4285
As above answers already mentioned @PathVariable should be used, I thought to clear the confusion between @PathVariable & @PathParam.
Most people get confused on this part because Spring and other rest implementation like Jersey use sightly different annotations for the same thing.
@QueryParam
in Jersey is @RequestParam
in Spring Rest API.
@PathParam
in Jersey is @PathVariable
in Spring Rest API.
Upvotes: 14
Reputation: 842
id
should be Long
instead of String
at @PathVariable
. If so, then ...
@RequestMapping(value="/person/get/{id}", method=RequestMethod.GET, produces="application/json")
public @ResponseBody Person getPersonById(@PathVariable("id") Long id) {
return personService.getPersonById(id);
}
Upvotes: 1
Reputation: 2470
The annotation to get path variable is @PathVariable. It looks like you have used @PathParam instead which is incorrect.
Check this out for more details:
Upvotes: 66