Spring + jqGrid
GridTestMapper.xml
GridTestVO / GridTestResultVO
public class GridTestVO { private int bno; private String title; private String content; private String writer; private String cnt; private String regdate; private String enabled; public int getBno() { return bno; } public void setBno(int bno) { this.bno = bno; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getWriter() { return writer; } public void setWriter(String writer) { this.writer = writer; } public String getCnt() { return cnt; } public void setCnt(String cnt) { this.cnt = cnt; } public String getRegdate() { return regdate; } public void setRegdate(String regdate) { this.regdate = regdate; } public String getEnabled() { return enabled; } public void setEnabled(String enabled) { this.enabled = enabled; } }
public class GridTestResultVO extends GridTestVO { private int rnum; private int total; private int page; private int records; private Listrows; public int getRnum() { return rnum; } public void setRnum(int rnum) { this.rnum = rnum; } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; } public int getPage() { return page; } public void setPage(int page) { this.page = page; } public int getRecords() { return records; } public void setRecords(int records) { this.records = records; } public List getRows() { return rows; } public void setRows(List rows) { this.rows = rows; } }
GridTestDAO / GridTestDAOImpl
public interface GridTestDAO { public ListgetAllBoard(HashMap hashMap); }
@Repository public class GridTestDAOImpl implements GridTestDAO { @Inject SqlSession sqlSession; private static String namespace = "com.kiosk.mapper.articleB"; @Override public ListgetAllBoard(HashMap hashMap){ return sqlSession.selectList(namespace+".getAllBoard", hashMap); }; }
GridTestService / GridTestServiceImpl
public interface GridTestService { public ListgetAllBoard(HashMap hashMap); }
@Service public class GridTestServiceImpl { @Inject GridTestDAO GridTestDAO; public ListgetAllBoard(HashMap hashMap) { return GridTestDAO.getAllBoard(hashMap); } }
Controller
@Controller public class GridTestController { private final Log logger = LogFactory.getLog(getClass()); @Autowired GridTestServiceImpl jsonService; @RequestMapping(value = "/boardList", method = RequestMethod.POST) public @ResponseBody Object getUserList(HttpServletRequest request, HttpServletResponse response, @RequestParam boolean _search, @RequestParam long nd, @RequestParam int rows, @RequestParam int page, @RequestParam String sidx, @RequestParam String sord) throws JsonGenerationException, JsonMappingException, IOException { logger.debug("search = " + _search + " : nd = " + nd + " : rows = " + rows + " : pages = " + page + " : sidx = " + sidx + " : sord =" + sord); HashMapparams = new HashMap (); int start = ((page - 1) * rows) + 1; int limit = (start + rows) - 1; System.err.println("start = " + start + " : limit =" + limit); params.put("start", start); params.put("limit", limit); List jsonExtList = jsonService.getAllBoard(params); ObjectMapper mapper = new ObjectMapper(); Map modelMap = new HashMap (); // total = Total Page // record = Total Records // rows = list data // page = current page double total = (double) jsonExtList.get(0).getTotal() / rows; System.err.println(total); modelMap.put("total", (int) Math.ceil(total)); modelMap.put("records", jsonExtList.get(0).getTotal()); modelMap.put("rows", jsonExtList); modelMap.put("page", page); String value = mapper.writeValueAsString(modelMap); logger.debug(value); System.err.println(value); return jsonExtList; } @RequestMapping(value = "/boardEdit", method = RequestMethod.POST) public String userCreate(JSONtestVO JSONtestVO, @RequestParam String oper) { logger.debug(oper); logger.debug(GridTestVO.getBno() + " : " + GridTestVO.getTitle() + " : " + GridTestVO.getContent() + " : " + GridTestVO.getRegDate() + " : " + GridTestVO.getCnt()); int resultValue = 0; if (oper.equals("edit")) { resultValue = jsonService.update(GridTestVO); } else if (oper.equals("del")) { resultValue = jsonService.deleteUser(GridTestVO); } else if (oper.equals("add")) { resultValue = jsonService.saveUser(GridTestVO); } return "/boardList"; } }
JSP부분
$.extend($.jgrid.edit, { closeAfterAdd : true, recreateForm : true, reloadAfterSubmit : false, left : 100, top : 100, dataheight : '100%', width : 500, addCaption : "추가", editCaption : "편집", bSubmit : "저장-전송", bCancel : "취소", bClose : "닫기", saveData : "Data has been changed! Save changes?", bYes : "Yes", bNo : "No", bExit : "Cancel" }); });