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
Post a Comment