@RequestMapping("/search") public ModelAndView search(String name) { List<User> list = service.findByName(name); ModelAndView mv = new ModelAndView(); mv.addObject("list", list); mv.setViewName("welcome"); return mv; }
@RequestMapping("/") public ModelAndView welcome() { ModelAndView mv = new ModelAndView(); List<User> list = service.findByLimit(30); mv.addObject("list", list); mv.setViewName("welcome"); return mv; }
@RequestMapping("/handleupdate") public ModelAndView handleUpdate(@Valid User user, BindingResult result) { ModelAndView mv = new ModelAndView(); if (result.hasFieldErrors()) { List<FieldError> list1 = result.getFieldErrors(); List<String> list = new LinkedList<String>(); Iterator<FieldError> it = list1.iterator(); while (it.hasNext()) { FieldError f = (FieldError) it.next(); String s = f.getDefaultMessage(); list.add(s); } mv.addObject("errors", list); mv.setViewName("error"); return mv; } else { service.updateUser(user); mv.setView(new RedirectView("/")); return mv; } }
@RequestMapping("/handledelete") public String handleDelete(@RequestParam("id") long id) { service.deleteById(id); return "redirect:/"; }