示例#1
0
 @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;
 }
示例#2
0
 @RequestMapping("/")
 public ModelAndView welcome() {
   ModelAndView mv = new ModelAndView();
   List<User> list = service.findByLimit(30);
   mv.addObject("list", list);
   mv.setViewName("welcome");
   return mv;
 }
示例#3
0
 @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;
   }
 }
示例#4
0
 @RequestMapping("/handledelete")
 public String handleDelete(@RequestParam("id") long id) {
   service.deleteById(id);
   return "redirect:/";
 }