From 2048ee7531c04baac3535609b971925b84ab1884 Mon Sep 17 00:00:00 2001 From: yuyang Date: Sun, 15 Mar 2015 14:35:47 +0800 Subject: [PATCH] make the code beautiful --- .../samples/petclinic/web/OwnerController.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java index ecbbce559..cbb8098fc 100644 --- a/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/web/OwnerController.java @@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.support.SessionStatus; import org.springframework.web.servlet.ModelAndView; @@ -96,13 +97,11 @@ public class OwnerController { // no owners found result.rejectValue("lastName", "notFound", "not found"); return "owners/findOwners"; - } - else if (results.size() == 1) { - // 1 owner found - owner = results.iterator().next(); - return "redirect:/owners/" + owner.getId(); - } - else { + } else if (results.size() == 1) { + // 1 owner found + owner = results.iterator().next(); + return "redirect:/owners/" + owner.getId(); + } else { // multiple owners found model.put("selections", results); return "owners/ownersList"; @@ -140,4 +139,9 @@ public class OwnerController { return mav; } + @RequestMapping("/owners/print") + @ResponseBody + public String printOwner() { + return "json"; + } }