From c4770ac40f83ee773426004fd8a4168b57a37aa5 Mon Sep 17 00:00:00 2001 From: karan Date: Fri, 24 Jul 2020 01:08:45 -0400 Subject: [PATCH] add another defaultpathvariable method --- .../pathvariable/PathVariableAnnotationController.java | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 624ba2d105..37e104f354 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 @@ -66,6 +66,16 @@ public class PathVariableAnnotationController { } } + @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) {