13.5.6 公告管理 处理公告的NoticeController
代码如下:
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 126 127 128 129 130 131 132 133 134 135 136 package org.fkit.hrm.controller;import java.util.List;import javax.servlet.http.HttpSession;import org.fkit.hrm.domain.Notice;import org.fkit.hrm.domain.User;import org.fkit.hrm.service.HrmService;import org.fkit.hrm.util.common.HrmConstants;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 NoticeController { @Autowired @Qualifier("hrmService") private HrmService hrmService; @RequestMapping(value = "/notice/selectNotice") public String selectNotice (Model model, Integer pageIndex, @ModelAttribute Notice notice) { PageModel pageModel = new PageModel (); if (pageIndex != null ) { pageModel.setPageIndex(pageIndex); } List<Notice> notices = hrmService.findNotice(notice, pageModel); model.addAttribute("notices" , notices); model.addAttribute("pageModel" , pageModel); return "notice/notice" ; } @RequestMapping(value = "/notice/previewNotice") public String previewNotice (Integer id, Model model) { Notice notice = hrmService.findNoticeById(id); model.addAttribute("notice" , notice); return "notice/previewNotice" ; } @RequestMapping(value = "/notice/removeNotice") public ModelAndView removeNotice (String ids, ModelAndView mv) { String[] idArray = ids.split("," ); for (String id : idArray) { hrmService.removeNoticeById(Integer.parseInt(id)); } mv.setViewName("redirect:/notice/selectNotice" ); return mv; } @RequestMapping(value = "/notice/addNotice") public ModelAndView addNotice (String flag, @ModelAttribute Notice notice, ModelAndView mv, HttpSession session) { if (flag.equals("1" )) { mv.setViewName("notice/showAddNotice" ); } else { User user = (User) session.getAttribute(HrmConstants.USER_SESSION); notice.setUser(user); hrmService.addNotice(notice); mv.setViewName("redirect:/notice/selectNotice" ); } return mv; } @RequestMapping(value = "/notice/updateNotice") public ModelAndView updateNotice (String flag, @ModelAttribute Notice notice, ModelAndView mv, HttpSession session) { if (flag.equals("1" )) { Notice target = hrmService.findNoticeById(notice.getId()); mv.addObject("notice" , target); mv.setViewName("notice/showUpdateNotice" ); } else { hrmService.modifyNotice(notice); mv.setViewName("redirect:/notice/selectNotice" ); } return mv; } }
单击左侧菜单公告管理 下面的添加公告 命令,跳转到添加公告界面。 输入需要添加的公告标题和公告内容,单击添加 按钮,若添加成功则跳转到公告查询
界面,显示所有公告信息。 选择每一行公告最后一列的预览 按钮,则可以预览公告内容。 输入公告名称和公告内容,单击搜索 按钮可以完成模糊査询功能
选择每一行的”操作”按钮,可以进入修改页面
,对选中的公告进行修改操作
。 选择每一行第一列的复选框,单击删除 按钮,则可以对选中的公告进行删除操作