@RequestMapping(method = RequestMethod.POST) public String registerNewMember( @Valid @ModelAttribute("newMember") Member newMember, BindingResult result, Model model) { if (!result.hasErrors()) { memberDao.register(newMember); return "redirect:/"; } else { model.addAttribute("members", memberDao.findAllOrderedByName()); return "index"; } }
@RequestMapping(method = RequestMethod.GET) public String displaySortedMembers(Model model) { model.addAttribute("newMember", new Member()); model.addAttribute("members", memberDao.findAllOrderedByName()); return "index"; }