13.5.3 部门管理
处理部门的DeptContro11er
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
| package org.fkit.hrm.controller;
import java.util.List; import org.fkit.hrm.domain.Dept; import org.fkit.hrm.service.HrmService; import org.fkit.hrm.util.tag.PageModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.servlet.ModelAndView;
@Controller public class DeptController {
@Autowired @Qualifier("hrmService") private HrmService hrmService;
@RequestMapping(value = "/dept/selectDept") public String selectDept(Model model, Integer pageIndex, @ModelAttribute Dept dept) { System.out.println("selectDept -->>"); System.out.println("pageIndex = " + pageIndex); System.out.println("dept = " + dept); PageModel pageModel = new PageModel(); System.out.println("getPageIndex = " + pageModel.getPageIndex()); System.out.println("getPageSize = " + pageModel.getPageSize()); System.out.println("getRecordCount = " + pageModel.getRecordCount()); if (pageIndex != null) { pageModel.setPageIndex(pageIndex); } List<Dept> depts = hrmService.findDept(dept, pageModel); model.addAttribute("depts", depts); model.addAttribute("pageModel", pageModel); return "dept/dept";
}
@RequestMapping(value = "/dept/removeDept") public ModelAndView removeDept(String ids, ModelAndView mv) { String[] idArray = ids.split(","); for (String id : idArray) { hrmService.removeDeptById(Integer.parseInt(id)); } mv.setViewName("redirect:/dept/selectDept"); return mv; }
@RequestMapping(value = "/dept/addDept") public ModelAndView addDept(String flag, @ModelAttribute Dept dept, ModelAndView mv) { if (flag.equals("1")) { mv.setViewName("dept/showAddDept"); } else { hrmService.addDept(dept); mv.setViewName("redirect:/dept/selectDept"); } return mv; }
@RequestMapping(value = "/dept/updateDept") public ModelAndView updateDpet(String flag, @ModelAttribute Dept dept, ModelAndView mv) { if (flag.equals("1")) { Dept target = hrmService.findDeptById(dept.getId()); mv.addObject("dept", target); mv.setViewName("dept/showUpdateDept"); } else { hrmService.modifyDept(dept); mv.setViewName("redirect:/dept/selectDept"); } return mv; } }
|
单击左侧菜单部门管理下面的添加部门命令,跳转到添加部门界面。
输入需要添加的部门名称和详细描述,单击添加按钮,若添加成功则跳转到部门查询界面
,显示所有部门信息。
输入部门名称,单击搜索按钮可以完成模糊査询功能
。
选择每一行最后一列的操作按钮,可以进入修改页面,对选中的部门进行修改操作
。
选择每一行第一列的复选框,单击删除按钮,则可以对选中的部门进行删除操作
。