How to User Path variable

 

How to User Path variable

@PathVariable  is used for add the variable in the path of your URL and use into the code 


@RestController

@RequestMapping(path = "/by")

public class ByWorldController {

@GetMapping(path = "/hello-world/path-variable/{name}/{gender}")

public HelloWorldBean helloWorldPathVariable(@PathVariable String name, @PathVariable String gender) {

         if(gender.equalsIgnoreCase("m")) {

                 return new HelloWorldBean(String.format("Hello Mr %s",name));

         } else if(gender.equalsIgnoreCase("f")) {

                 return new HelloWorldBean(String.format("Hello Mrs %s",name));

         }

         return new HelloWorldBean(String.format("Hello %s",name));       

  }

}


Comments

Popular posts from this blog

Introduction of RESTful Web Service

Learn JPA and Hibernate

Implementing Dynamic Filtering for Rest API