Posts

Showing posts with the label @PathVariable

Spring @PathVariable Annotation Example

Image
In this section we will learn about  @ PathVariable  Annotation.   The  @ PathVariable   annotation used on a method argument to bind it to the value of 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 value  - alias for name With the  @PathVariable  annotation, we bind the request URL template path variable to the method variable.  For instance, with the  /India/Knowledgefactory/  URL, the  India  value is bind to the  country  variable and " Knowledgefactory " value to the  name  variable. @GetMapping ( path = " /users/{country}/{name} " ) public User getUserByCountryAndName( @PathVariable String country, @PathVariable ( name = " name " ) String name) { ........... } The following example creates a Spring Boot web application which uses @P...