@RequestMapping(value = "") public String list( @RequestParam(value = "sortType", defaultValue = "auto") String sortType, @RequestParam(value = "page", defaultValue = "1") int pageNumber, Model model, ServletRequest request) { model.addAttribute("action", "create"); model.addAttribute("coachs", coachService.getAllCoachs()); return "coach/coachList"; }
@RequestMapping(value = "create", method = RequestMethod.POST) public String create( @Valid Coach newCoach, @RequestParam("file") CommonsMultipartFile mediaFile, RedirectAttributes redirectAttributes) { try { createFile(mediaFile, newCoach); } catch (Exception e) { e.printStackTrace(); } coachService.saveCoach(newCoach); redirectAttributes.addFlashAttribute("message", "创建教练成功"); return "redirect:/coach"; }
@RequestMapping(value = "delete/{id}") public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAttributes) { coachService.deleteCoach(id); redirectAttributes.addFlashAttribute("message", "删除教练成功"); return "redirect:/coach/"; }
@RequestMapping(value = "update", method = RequestMethod.POST) public String update(@Valid Coach coach, RedirectAttributes redirectAttributes) { coachService.updateCoach(coach); redirectAttributes.addFlashAttribute("message", "更新教练成功"); return "redirect:/coach/"; }
@RequestMapping(value = "update/{id}", method = RequestMethod.GET) public String updateForm(@PathVariable("id") Long id, Model model) { model.addAttribute("coach", coachService.getCoach(id)); model.addAttribute("action", "update"); return "coach/coachForm"; }