Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting null with @pathparam and @requestmapping

Tags:

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.

like image 960
Ram Kowsu Avatar asked Jan 15 '17 03:01

Ram Kowsu


People also ask

Can we use RequestParam and PathVariable together?

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.

What is difference between @PathParam and @PathVariable?

@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.

What is @PathParam in Spring boot?

@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.


1 Answers

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

like image 194
DeepakV Avatar answered Sep 20 '22 06:09

DeepakV