예제 #1
0
 /**
  * 删除菜单记录.
  *
  * @param id
  * @param redirectAttributes
  * @return
  */
 @RequestMapping(value = "delete/{id}")
 public String delete(@PathVariable("id") Long id, RedirectAttributes redirectAttributes) {
   Sidebar sidebar = sidebarService.getSidebar(id);
   sidebarService.deleteSidebar(id);
   redirectAttributes.addFlashAttribute("message", "删除菜单" + sidebar.getName() + "成功");
   return "redirect:/sidebar";
 }
예제 #2
0
 /**
  * 所有RequestMapping方法调用前的Model准备方法, 实现预处理部分绑定的效果,先根据form的id从数据库查出Sidebar对象,再把Form提交的内容绑定到该对象上。
  * 因为仅update()方法的form中有id属性,因此仅在update时实际执行.
  */
 @ModelAttribute
 public void getSidebar(
     @RequestParam(value = "id", defaultValue = "-1") Long id,
     @RequestParam(value = "preSidebar.id", defaultValue = "-1") Long preSidebarId,
     Model model) {
   if (id != -1) {
     Sidebar sidebar = sidebarService.getSidebar(id);
     if (preSidebarId > 0) {
       sidebar.setPreSidebar(sidebarService.getSidebar(preSidebarId));
     } else {
       sidebar.setPreSidebar(null);
     }
     model.addAttribute("sidebar", sidebar);
   }
 }
예제 #3
0
 /**
  * 提交更新的菜单信息.
  *
  * @param sidebar
  * @param redirectAttributes
  * @return
  */
 @RequestMapping(value = "update", method = RequestMethod.POST)
 public String update(
     @Valid @ModelAttribute("sidebar") Sidebar sidebar, RedirectAttributes redirectAttributes) {
   sidebarService.saveSidebar(sidebar);
   redirectAttributes.addFlashAttribute("message", "更新菜单‘" + sidebar.getName() + "’成功");
   return "redirect:/sidebar";
 }