package geoinfo.admins.board; import egovframework.rte.psl.dataaccess.util.EgovMap; import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo; import geoinfo.admins.board.service.FreqAskQueService; import geoinfo.session.UserInfo; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller public class FreqAskQueController { @Resource(name = "freqAskQueService") private FreqAskQueService masterService; @RequestMapping(value = "admins/board/11.do") public String board00( @RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } /** pageing */ PaginationInfo paginationInfo = new PaginationInfo(); if (params.get("pageIndex") == null || "".equals(params.get("pageIndex"))) { paginationInfo.setCurrentPageNo(1); params.put("pageIndex", 1); } else { paginationInfo.setCurrentPageNo(Integer.valueOf((String) params.get("pageIndex"))); } paginationInfo.setRecordCountPerPage(10); paginationInfo.setPageSize(10); params.put("firstRecordIndex", paginationInfo.getFirstRecordIndex()); params.put("recordCountPerPage", paginationInfo.getRecordCountPerPage()); List result = masterService.selectInfo(params); paginationInfo.setTotalRecordCount(Integer.valueOf(((EgovMap) result.get(0)).get("totalrows").toString())); model.addAttribute("LT", "<"); model.addAttribute("GT", ">"); model.addAttribute("br", "\r"); model.addAttribute("paginationInfo", paginationInfo); model.addAttribute("result", result); return "admins/board/11"; } @RequestMapping(value = "admins/board/11-write.do") public String write11( @RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } return "admins/board/11-write"; } @RequestMapping(value = "admins/board/11-write-post", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) public ModelMap saveInfo(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { HashMap jsonMap = new HashMap(); String subject = params.get("subject").toString(); String contents = params.get("contents").toString(); if(subject != null) { subject = subject.replaceAll("<","<"); subject = subject.replaceAll(">",">"); params.put("subject", subject); } if(contents != null){ contents = contents.replaceAll("<","<"); contents = contents.replaceAll(">",">"); contents = contents.replaceAll("\n","
"); params.put("contents", contents); } try{ params.put("password", "kictgis1234"); int maxIdx = masterService.getMaxIdx(); params.put("maxIdx", maxIdx); params.put("cls", "2"); masterService.saveInfo(params); jsonMap.put("success", true); } catch (SQLException Ex) { jsonMap.put("success", false); } model.addAttribute("jsonView", jsonMap); // JSON으로 리턴하기 위해서는 모델키를 'jsonView'로 지정해야함 return model; } @RequestMapping(value = "admins/board/11-delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) public ModelMap deleteInfo(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { HashMap jsonMap = new HashMap(); try { masterService.deleteInfo(params); jsonMap.put("success", true); } catch (SQLException Ex) { jsonMap.put("success", false); } model.addAttribute("jsonView", jsonMap); // JSON으로 리턴하기 위해서는 모델키를 'jsonView'로 지정해야함 return model; } @RequestMapping(value = "admins/board/11-modify.do") public String modifyInfo(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { if (!UserInfo.isValidSession(request, response, "admin")) { return ""; } EgovMap result = masterService.selectModifyInfo(params); String subject = result.get("subject").toString(); String content = result.get("content").toString(); if(subject != null) { subject = subject.replaceAll("<","<"); subject = subject.replaceAll(">",">"); result.put("subject", subject); } if(content != null) { content = content.replaceAll("<","<"); content = content.replaceAll(">",">"); content = content.replaceAll("
","\n"); result.put("content", content); } model.addAttribute("result", result); return "admins/board/11-modify"; } @RequestMapping(value = "admins/board/11-modify-post", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) public ModelMap updateInfo(@RequestParam HashMap params, ModelMap model, HttpServletResponse response, HttpServletRequest request) throws Exception { HashMap jsonMap = new HashMap(); String subject = params.get("subject").toString(); String content = params.get("content").toString(); if(subject != null) { subject = subject.replaceAll("<","<"); subject = subject.replaceAll(">",">"); params.put("subject", subject); } if(content != null) { content = content.replaceAll("<","<"); content = content.replaceAll(">",">"); content = content.replaceAll("\n","
"); params.put("content", content); } try{ masterService.updateInfo(params); jsonMap.put("success", true); } catch (SQLException Ex) { jsonMap.put("success", false); } model.addAttribute("jsonView", jsonMap); // JSON으로 리턴하기 위해서는 모델키를 'jsonView'로 지정해야함 return model; } }