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.
The @PathVariable annotation is used for data passed in the URI (e.g. RESTful web services) while @RequestParam is used to extract the data found in query parameters. These annotations can be mixed together inside the same controller. @PathParam is a JAX-RS annotation that is equivalent to @PathVariable in Spring.
@PathParam: it is used to inject the value of named URI path parameters that were defined in @Path expression. @Pathvariable: This annotation is used to handle template variables in the request URI mapping ,and used them as method parameters.
@PathVariable is a Spring annotation which indicates that a method parameter should be bound to a URI template variable. It has the following optional elements: name - name of the path variable to bind to. required - tells whether the path variable is required.
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:
requestparam-vs-pathvariable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With