@RequestMapping(value = "add", method = RequestMethod.POST) public String add(String title, String startDate, String endDate, String member) throws Exception { Project project = new Project(); project.setTitle(title); project.setStartDate(Date.valueOf(startDate)); project.setEndDate(Date.valueOf(endDate)); project.setMember(member); projectDao.insert(project); return "redirect:list.do"; }
@RequestMapping("update") public String update( int no, String title, String startDate, String endDate, String member, Model model) throws Exception { Project project = new Project(); project.setTitle(title); project.setStartDate(Date.valueOf(startDate)); project.setEndDate(Date.valueOf(endDate)); project.setMember(member); project.setNo(no); if (projectDao.update(project) <= 0) { model.addAttribute("errorCode", "401"); return "project/ProjectAuthError"; } return "redirect:list.do"; }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { int pageNo = 1; int pageSize = 10; if (request.getParameter("pageNo") != null) { pageNo = Integer.parseInt(request.getParameter("pageNo")); } if (request.getParameter("pageSize") != null) { pageSize = Integer.parseInt(request.getParameter("pageSize")); } String keyword = "no"; String align = "desc"; if (request.getParameter("keyword") != null) { keyword = request.getParameter("keyword"); } if (request.getParameter("align") != null) { align = request.getParameter("align"); } response.setContentType("text/plain;charset=UTF-8"); PrintWriter out = response.getWriter(); out.printf("%-3s %-20s %-10s %-10s %-40s\n", "No", "Title", "Start", "End", "Members"); ApplicationContext iocContext = (ApplicationContext) this.getServletContext().getAttribute("iocContainer"); ProjectDao projectDao = iocContext.getBean(ProjectDao.class); for (Project project : projectDao.selectList(pageNo, pageSize, keyword, align)) { out.printf( "% 3d %-20s %3$tY-%3$tm-%3$td %4$s %5$-40s\n", project.getNo(), project.getTitle(), project.getStartDate(), project.getEndDate(), project.getMember()); } RequestDispatcher rd = request.getRequestDispatcher("/copyright"); rd.include(request, response); } catch (Exception e) { RequestDispatcher rd = request.getRequestDispatcher("/error"); rd.forward(request, response); } }
@Override public void service(HashMap<String, Object> params) { int pageNo = 1; int pageSize = 10; if (params.get("pageNo") != null) { pageNo = Integer.parseInt((String) params.get("pageNo")); } if (params.get("pageSize") != null) { pageSize = Integer.parseInt((String) params.get("pageSize")); } // 정렬 처리 String keyword = "no"; String align = "desc"; if (params.get("keyword") != null) { keyword = (String) params.get("keyword"); } if (params.get("align") != null) { align = (String) params.get("align"); } PrintStream out = (PrintStream) params.get("out"); out.printf("%-3s %-20s %-10s %-10s %-40s\n", "No", "Title", "Start", "End", "Members"); for (Project project : projectDao.selectList(pageNo, pageSize, keyword, align)) { out.printf( "% 3d %-20s %3$tY-%3$tm-%3$td %4$s %5$-40s\n", project.getNo(), project.getTitle(), project.getStartDate(), project.getEndDate(), project.getMember()); } }