diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java index 37e104f354..0cbd852095 100644 --- a/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/pathvariable/PathVariableAnnotationController.java @@ -10,80 +10,80 @@ import java.util.Optional; @RestController public class PathVariableAnnotationController { - @GetMapping("/api/employees/{id}") - @ResponseBody - public String getEmployeesById(@PathVariable String id) { - return "ID: " + id; - } + @GetMapping("/api/employees/{id}") + @ResponseBody + public String getEmployeesById(@PathVariable String id) { + return "ID: " + id; + } - @GetMapping("/api/employeeswithvariable/{id}") - @ResponseBody - public String getEmployeesByIdWithVariableName(@PathVariable("id") String employeeId) { - return "ID: " + employeeId; - } + @GetMapping("/api/employeeswithvariable/{id}") + @ResponseBody + public String getEmployeesByIdWithVariableName(@PathVariable("id") String employeeId) { + return "ID: " + employeeId; + } - @GetMapping("/api/employees/{id}/{name}") - @ResponseBody - public String getEmployeesByIdAndName(@PathVariable String id, @PathVariable String name) { - return "ID: " + id + ", name: " + name; - } + @GetMapping("/api/employees/{id}/{name}") + @ResponseBody + public String getEmployeesByIdAndName(@PathVariable String id, @PathVariable String name) { + return "ID: " + id + ", name: " + name; + } - @GetMapping("/api/employeeswithmapvariable/{id}/{name}") - @ResponseBody - public String getEmployeesByIdAndNameWithMapVariable(@PathVariable Map pathVarsMap) { - String id = pathVarsMap.get("id"); - String name = pathVarsMap.get("name"); - if (id != null && name != null) { - return "ID: " + id + ", name: " + name; - } else { - return "Missing Parameters"; - } - } + @GetMapping("/api/employeeswithmapvariable/{id}/{name}") + @ResponseBody + public String getEmployeesByIdAndNameWithMapVariable(@PathVariable Map pathVarsMap) { + String id = pathVarsMap.get("id"); + String name = pathVarsMap.get("name"); + if (id != null && name != null) { + return "ID: " + id + ", name: " + name; + } else { + return "Missing Parameters"; + } + } - @GetMapping(value = { "/api/employeeswithrequired", "/api/employeeswithrequired/{id}" }) - @ResponseBody - public String getEmployeesByIdWithRequired(@PathVariable String id) { - return "ID: " + id; - } + @GetMapping(value = { "/api/employeeswithrequired", "/api/employeeswithrequired/{id}" }) + @ResponseBody + public String getEmployeesByIdWithRequired(@PathVariable String id) { + return "ID: " + id; + } - @GetMapping(value = { "/api/employeeswithrequiredfalse", "/api/employeeswithrequiredfalse/{id}" }) - @ResponseBody - public String getEmployeesByIdWithRequiredFalse(@PathVariable(required = false) String id) { - if (id != null) { - return "ID: " + id; - } else { - return "ID missing"; - } - } + @GetMapping(value = { "/api/employeeswithrequiredfalse", "/api/employeeswithrequiredfalse/{id}" }) + @ResponseBody + public String getEmployeesByIdWithRequiredFalse(@PathVariable(required = false) String id) { + if (id != null) { + return "ID: " + id; + } else { + return "ID missing"; + } + } - @GetMapping(value = { "/api/employeeswithoptional", "/api/employeeswithoptional/{id}" }) - @ResponseBody - public String getEmployeesByIdWithOptional(@PathVariable Optional id) { - if (id.isPresent()) { - return "ID: " + id.get(); - } else { - return "ID missing"; - } - } + @GetMapping(value = { "/api/employeeswithoptional", "/api/employeeswithoptional/{id}" }) + @ResponseBody + public String getEmployeesByIdWithOptional(@PathVariable Optional id) { + if (id.isPresent()) { + return "ID: " + id.get(); + } else { + return "ID missing"; + } + } - @GetMapping(value = { "/api/defaultemployeeswithoptional", "/api/defaultemployeeswithoptional/{id}" }) - @ResponseBody - public String getDefaultEmployeesByIdWithOptional(@PathVariable Optional id) { - if (id.isPresent()) { - return "ID: " + id.get(); - } else { - return "ID: Default Employee"; - } - } + @GetMapping(value = { "/api/defaultemployeeswithoptional", "/api/defaultemployeeswithoptional/{id}" }) + @ResponseBody + public String getDefaultEmployeesByIdWithOptional(@PathVariable Optional id) { + if (id.isPresent()) { + return "ID: " + id.get(); + } else { + return "ID: Default Employee"; + } + } - @GetMapping(value = { "/api/employeeswithmap/{id}", "/api/employeeswithmap" }) - @ResponseBody - public String getEmployeesByIdWithMap(@PathVariable Map pathVarsMap) { - String id = pathVarsMap.get("id"); - if (id != null) { - return "ID: " + id; - } else { - return "ID missing"; - } - } + @GetMapping(value = { "/api/employeeswithmap/{id}", "/api/employeeswithmap" }) + @ResponseBody + public String getEmployeesByIdWithMap(@PathVariable Map pathVarsMap) { + String id = pathVarsMap.get("id"); + if (id != null) { + return "ID: " + id; + } else { + return "ID missing"; + } + } }