참고로 전 spring framework은 직장인 환급과정(야간) 교육때 기초만 배웠으며
ibatis도 그때 잠시(select문) 다뤄 본 것이 전부 입니다.
그때의 기초로 배운 부분과 책을 참고하여 나름 구현한 것이니
실무하고는 많이(아주 많이) 다를 수 있습니다..^^;;;
좀 더 필요한 부분을 구현해야 겠지만
우선은 이 정도로 마무리 할려고 합니다.
(하단의 게시판 소스도 예외처리부터 시작해서 많은 부분이 빠져 있는데
그 부분은 나중에 추가로 계속 업데이트를 하던지 따로 정리해서 포스팅 하겠습니다...)
필요한 부분이나 제가 추가로 공부하는 것에 대해서는 계속 업데이트 예정입니다..^^
BoardVO.java
PageNavigation.java
BoardMultiController.java
BoardLogic.java
BoardLogicImpl.java
BoardDao.java
BoardDaoImpl.java
web.xml
applicationContext.xml
board-servlet.xml
SqlMapConfig.xml
board.xml
===============================================================================================================
boardList.jsp
boardDetail.jsp
boardModify.jsp
boardInsert.jsp
boardList.jsp 화면
ibatis도 그때 잠시(select문) 다뤄 본 것이 전부 입니다.
그때의 기초로 배운 부분과 책을 참고하여 나름 구현한 것이니
실무하고는 많이(아주 많이) 다를 수 있습니다..^^;;;
좀 더 필요한 부분을 구현해야 겠지만
우선은 이 정도로 마무리 할려고 합니다.
(하단의 게시판 소스도 예외처리부터 시작해서 많은 부분이 빠져 있는데
그 부분은 나중에 추가로 계속 업데이트를 하던지 따로 정리해서 포스팅 하겠습니다...)
필요한 부분이나 제가 추가로 공부하는 것에 대해서는 계속 업데이트 예정입니다..^^
BoardVO.java
package source.board.vo; public class BoardVO { private int boardSeq; private String boardType; private int step; private String title; private String content; private String ip; private String deleteYn; private String regiDt; private String regiUser; private String modiDt; private String modiUser; public int getBoardSeq() { return boardSeq; } public void setBoardSeq(int boardSeq) { this.boardSeq = boardSeq; } public String getBoardType() { return boardType; } public void setBoardType(String boardType) { this.boardType = boardType; } public int getStep() { return step; } public void setStep(int step) { this.step = step; } 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 getIp() { return ip; } public void setIp(String ip) { this.ip = ip; } public String getDeleteYn() { return deleteYn; } public void setDeleteYn(String deleteYn) { this.deleteYn = deleteYn; } public String getRegiDt() { return regiDt; } public void setRegiDt(String regiDt) { this.regiDt = regiDt; } public String getRegiUser() { return regiUser; } public void setRegiUser(String regiUser) { this.regiUser = regiUser; } public String getModiDt() { return modiDt; } public void setModiDt(String modiDt) { this.modiDt = modiDt; } public String getModiUser() { return modiUser; } public void setModiUser(String modiUser) { this.modiUser = modiUser; } @Override public String toString() { return "BoardVO [boardSeq=" + boardSeq + ", boardType=" + boardType + ", content=" + content + ", deleteYn=" + deleteYn + ", ip=" + ip + ", modiDt=" + modiDt + ", modiUser=" + modiUser + ", regiDt=" + regiDt + ", regiUser=" + regiUser + ", step=" + step + ", title=" + title + "]"; } } |
PageNavigation.java
package source.util; import java.util.Enumeration; import javax.servlet.http.HttpServletRequest; public class PageNavigation { private int firstPageNo; private int lastPageNo; private int prevPageNo; private int nextPageNo; private int beginPageNo; private int endPageNo; private int beginRowNo; private int endRowNo; private int totalCnt; private int currentPageNo; private int pageRowCnt; private HttpServletRequest req; public int getBeginRowNo() { return beginRowNo; } public int getEndRowNo() { return endRowNo; } public int getCurrentPageNo() { return currentPageNo; } public void setCurrentPageNo(int currentPageNo) { this.currentPageNo = currentPageNo; } public void setNavigationInfo(int totalCnt, int pageRowCnt, int currentPageNo, HttpServletRequest request){ this.totalCnt = totalCnt; this.pageRowCnt = pageRowCnt; this.currentPageNo = currentPageNo; this.req = request; this.firstPageNo = 1; this.lastPageNo = (totalCnt / pageRowCnt); if((totalCnt % pageRowCnt) > 0){ lastPageNo++; } this.beginPageNo = ((currentPageNo - 1) / 10) * 10 + 1; this.endPageNo = beginPageNo + 9; if(endPageNo > lastPageNo){ endPageNo = lastPageNo; } this.prevPageNo = beginPageNo - 1; if(prevPageNo < firstPageNo){ prevPageNo = 1; } this.nextPageNo = endPageNo + 1; if(nextPageNo > lastPageNo){ nextPageNo = lastPageNo; } this.beginRowNo = (currentPageNo - 1) * pageRowCnt; this.endRowNo = (currentPageNo * pageRowCnt) + 1; } public String getNavigationStr(){ StringBuffer sb = new StringBuffer(); sb.append(""); sb.append("<a href='javascript:goPage("+firstPageNo+")'>" + firstPageNo + "</a> << "); sb.append("<a href='javascript:goPage("+prevPageNo+")'>" + prevPageNo + "</a> < "); for(int i = beginPageNo; i <= endPageNo; i++){ if(i == currentPageNo){ sb.append(" " + i + " "); }else{ sb.append(" <a href='javascript:goPage("+i+")'>[" + i + "]</a> "); } } sb.append(" > <a href='javascript:goPage("+nextPageNo+")'>" + nextPageNo + "</a>"); sb.append(" >> <a href='javascript:goPage("+lastPageNo+")'>" + lastPageNo + "</a>"); sb.append(""); return sb.toString(); } public String getMakeParamForm(){ Enumeration enu = req.getParameterNames(); StringBuffer sb = new StringBuffer(); sb.append("<form name='pageForm' method='post'>"); sb.append(" <input type='hidden' name='pageNo' value='"+currentPageNo+"'/>"); while(enu.hasMoreElements()){ String pName = (String)enu.nextElement(); String pValue = req.getParameter(pName); if(!pName.equals("pageNo")){ sb.append(" <input type='hidden' name='"+pName+"' value='"+pValue+"'/>"); } } sb.append("</form>"); sb.append(""); sb.append("<script type='text/javascript'>"); sb.append("function goPage(pageNo){"); sb.append(" var doc = document.pageForm;"); sb.append(" doc.pageNo.value = pageNo;"); sb.append("doc.action='boardList.sn';"); sb.append("doc.submit();"); sb.append(""); sb.append("}"); sb.append("</script>"); return sb.toString(); } } |
BoardMultiController.java
package source.board.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; import source.board.logic.BoardLogic; import source.board.vo.BoardVO; import source.util.PageNavigation; public class BoardMultiController extends MultiActionController { private BoardLogic boardLogic; public void setBoardLogic(BoardLogic boardLogic) { this.boardLogic = boardLogic; } //BoardList public ModelAndView onBoardList(HttpServletRequest request, HttpServletResponse response) throws Exception{ PageNavigation pageNavigation = new PageNavigation(); String currPageNo = request.getParameter("pageNo"); if(currPageNo == null || currPageNo.equals("")){ currPageNo = "1"; } int currentPageNo = Integer.parseInt(currPageNo); int pageRowCnt = 10; pageNavigation.setCurrentPageNo(currentPageNo); int totalCnt = boardLogic.boardListCnt(); pageNavigation.setNavigationInfo(totalCnt, pageRowCnt, currentPageNo, request); int beginRowNo = pageNavigation.getBeginRowNo(); int endRowNo = pageNavigation.getEndRowNo(); List<BoardVO> boardList = null; ModelAndView modelAndView = new ModelAndView(); try{ boardList = boardLogic.boardList(beginRowNo, endRowNo); modelAndView.setViewName("board/boardList"); modelAndView.addObject("boardList", boardList); modelAndView.addObject("pageNavigation", pageNavigation); }catch(Exception e){ modelAndView = new ModelAndView("error/error_common"); modelAndView.addObject("errorMsg", "System error~!!!"); } return modelAndView; } //boardDetail public ModelAndView onBoardDetail(HttpServletRequest request, HttpServletResponse response) throws Exception{ int boardSeq = Integer.parseInt(request.getParameter("boardSeq")); String act = request.getParameter("act"); BoardVO boardDetail = null; ModelAndView modelAndView = new ModelAndView(); try{ boardDetail = boardLogic.boardDetail(boardSeq); if(act.equals("d")){ modelAndView.setViewName("board/boardDetail"); }else if(act.equals("u")){ modelAndView.setViewName("board/boardModify"); } modelAndView.addObject("boardDetail", boardDetail); }catch(Exception e){ modelAndView = new ModelAndView("error/error_common"); modelAndView.addObject("errorMsg", "System error~!!!"); } return modelAndView; } //boardUpdate public ModelAndView onBoardUpdate(HttpServletRequest request, HttpServletResponse response) throws Exception{ int boardSeq = Integer.parseInt(request.getParameter("boardSeq")); String title = request.getParameter("title"); String content = request.getParameter("ir1"); String ip = request.getLocalAddr(); BoardVO boardVo = new BoardVO(); boardVo.setTitle(title); boardVo.setBoardSeq(boardSeq); boardVo.setContent(content); boardVo.setIp(ip); BoardVO boardDetail = null; int successCnt = 0; ModelAndView modelAndView = new ModelAndView(); try{ successCnt = boardLogic.boardUpdate(boardVo); if(successCnt > 0){ //exception boardDetail = boardLogic.boardDetail(boardSeq); modelAndView.setViewName("board/boardModify"); modelAndView.addObject("boardDetail", boardDetail); }else{ modelAndView = this.onBoardList(request, response); } }catch(Exception e){ modelAndView = new ModelAndView("error/error_common"); modelAndView.addObject("errorMsg", "System error~!!!"); } return modelAndView; } //boardDelete public ModelAndView onBoardDelete(HttpServletRequest request, HttpServletResponse response) throws Exception{ int boardSeq = Integer.parseInt(request.getParameter("boardSeq")); int successCnt = 0; ModelAndView modelAndView = null; try{ successCnt = boardLogic.boardDelete(boardSeq); if(successCnt > 0){ modelAndView = this.onBoardList(request, response); }else{ modelAndView = new ModelAndView("error/error_common"); modelAndView.addObject("errorMsg", "delete fail"); } }catch(Exception e){ modelAndView = new ModelAndView("error/error_common"); modelAndView.addObject("errorMsg", "System error~!!!"); } return modelAndView; } //onBoardMove public ModelAndView onBoardInsert(HttpServletRequest request, HttpServletResponse response) throws Exception{ String act = request.getParameter("act"); ModelAndView modelAndView = new ModelAndView(); if(act.equals("movePage")){ modelAndView.setViewName("board/boardInsert"); }else if(act.equals("insert")){ BoardVO boardVo = new BoardVO(); boardVo.setBoardType("001"); boardVo.setStep(1); boardVo.setTitle(request.getParameter("title")); boardVo.setContent(request.getParameter("ir1")); boardVo.setIp(request.getLocalAddr()); try{ int successCnt = boardLogic.boardInsert(boardVo); //successCnt = 1; modelAndView = this.onBoardList(request, response); }catch(Exception e){ modelAndView = new ModelAndView("error/error_common"); modelAndView.addObject("errorMsg", "System error~!!!"); } } return modelAndView; } } |
BoardLogic.java
package source.board.logic; import java.util.List; import source.board.vo.BoardVO; public interface BoardLogic { List<BoardVO> boardList(int beginRowNo, int endRowNo); BoardVO boardDetail(int boardSeq); int boardListCnt(); int boardUpdate(BoardVO boardVo); int boardDelete(int boardSeq); int boardInsert(BoardVO boardVo); } |
BoardLogicImpl.java
package source.board.logic; import java.util.List; import source.board.dao.BoardDao; import source.board.vo.BoardVO; public class BoardLogicImpl implements BoardLogic { private BoardDao boardDao; public void setBoardDao(BoardDao boardDao) { this.boardDao = boardDao; } @Override public List<BoardVO> boardList(int beginRowNo, int endRowNo) { // TODO Auto-generated method stub return boardDao.boardList(beginRowNo, endRowNo); } @Override public BoardVO boardDetail(int boardSeq) { // TODO Auto-generated method stub return boardDao.boardDetail(boardSeq); } @Override public int boardListCnt() { // TODO Auto-generated method stub return boardDao.boardListCount(); } @Override public int boardUpdate(BoardVO boardVo) { // TODO Auto-generated method stub return boardDao.boardUpdate(boardVo); } @Override public int boardDelete(int boardSeq) { // TODO Auto-generated method stub return boardDao.boardDelete(boardSeq); } @Override public int boardInsert(BoardVO boardVo) { // TODO Auto-generated method stub return boardDao.boardInsert(boardVo); } } |
BoardDao.java
package source.board.dao; import java.util.List; import source.board.vo.BoardVO; public interface BoardDao { List<BoardVO> boardList(int beginRowNo, int endRowNo); BoardVO boardDetail(int boardSeq); int boardListCount(); int boardUpdate(BoardVO boardVo); int boardDelete(int boardSeq); int boardInsert(BoardVO boardVo); } |
BoardDaoImpl.java
package source.board.dao; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; import source.board.vo.BoardVO; public class BoardDaoImpl extends SqlMapClientDaoSupport implements BoardDao { @Override public List<BoardVO> boardList(int beginRowNo, int endRowNo) { // TODO Auto-generated method stub Map map = new HashMap(); map.put("beginRowNo", beginRowNo); map.put("endRowNo", endRowNo); List<BoardVO> boardList = getSqlMapClientTemplate().queryForList("board.selectBoardList", map); return boardList; } @Override public BoardVO boardDetail(int boardSeq) { // TODO Auto-generated method stub BoardVO boardDetail = (BoardVO)getSqlMapClientTemplate().queryForObject("board.selectBoardDetail", boardSeq); return boardDetail; } @Override public int boardListCount() { // TODO Auto-generated method stub int boardCnt = (Integer)getSqlMapClientTemplate().queryForObject("board.selectBoardListCnt"); return boardCnt; } @Override public int boardUpdate(BoardVO boardVo) { // TODO Auto-generated method stub int successCnt = getSqlMapClientTemplate().update("board.update", boardVo); return successCnt; } @Override public int boardDelete(int boardSeq) { // TODO Auto-generated method stub int successCnt = getSqlMapClientTemplate().update("board.deleteBoard", boardSeq); return successCnt; } @Override public int boardInsert(BoardVO boardVo) { // TODO Auto-generated method stub int successCnt = 0; try{ int boardSeq = (Integer)getSqlMapClientTemplate().queryForObject("board.selectBoardSeq"); boardVo.setBoardSeq(boardSeq); getSqlMapClientTemplate().insert("board.insertBoard", boardVo); successCnt++; }catch(Exception e){ System.out.println(e.toString()); System.out.println(e.getMessage()); } return successCnt; } } |
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>snoopy</display-name> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>snoopy</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml /WEB-INF/board-servlet.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>snoopy</servlet-name> <url-pattern>*.sn</url-pattern> </servlet-mapping> </web-app> |
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- 1. dataSource 생성 --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.OracleDriver"></property> <property name="url" value="jdbc:oracle:thin:@111.222.333.444:1521:orcl"></property> <property name="username" value="XXXXXXX"></property> <property name="password" value="YYYYYYY"></property> </bean> <!-- 2. ibatis 코딩을 지원해주는 SqlMapClient 빈 생성 --> <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="/WEB-INF/SqlMapConfig.xml"></property> </bean> <!-- 3. 공통 빈 생성 - 그외의 빈은 myHome02-servlet.xml에서 설정 --> </beans> |
board-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <!-- HandlerMapping --> <bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/boardList.sn">boardMultiController</prop> <prop key="/boardDetail.sn">boardMultiController</prop> <prop key="/boardUpdate.sn">boardMultiController</prop> <prop key="/boardDelete.sn">boardMultiController</prop> <prop key="/boardInsert.sn">boardMultiController</prop> </props> </property> </bean> <!-- ViewResolver --> <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"> <value>org.springframework.web.servlet.view.JstlView</value> </property> <property name="prefix"> <value>jsp/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean> <bean id="boardMultiController" class="source.board.controller.BoardMultiController"> <property name="methodNameResolver" ref="methodNameResolver"></property> <property name="boardLogic" ref="boardLogic"></property> </bean> <bean id="methodNameResolver" class="org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver"> <property name="mappings"> <props> <prop key="/boardList.sn">onBoardList</prop> <prop key="/boardDetail.sn">onBoardDetail</prop> <prop key="/boardUpdate.sn">onBoardUpdate</prop> <prop key="/boardDelete.sn">onBoardDelete</prop> <prop key="/boardInsert.sn">onBoardInsert</prop> </props> </property> </bean> <bean id="boardLogic" class="source.board.logic.BoardLogicImpl"> <property name="boardDao" ref="boardDao"></property> </bean> <bean id="boardDao" class="source.board.dao.BoardDaoImpl"> <property name="sqlMapClient" ref="sqlMapClient"></property> </bean> </beans> |
SqlMapConfig.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMapConfig PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-config-2.dtd"> <sqlMapConfig> <settings useStatementNamespaces="true"/> <sqlMap resource="/query/board/board.xml"/> </sqlMapConfig> |
board.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <!-- Mapper 파일 --> <!-- 이름 충돌을 방지하기 위해 namespace를 사용 SqlMapConfig.xml에 <settings useStatementNamespaces="true"/> 설정이 지정되어 있는 경우 sql구문을 찾을 때 반드시 namespace값을 포함해야 한다. --> <sqlMap namespace="board"> <resultMap id="r_boardVo" class="source.board.vo.BoardVO"> <result property="boardSeq" column="BOARD_SEQ"/> <result property="boardType" column="BOARD_TYPE"/> <result property="step" column="STEP"/> <result property="title" column="TITLE"/> <result property="content" column="CONTENT" jdbcType="CLOB"/> <result property="ip" column="IP"/> <result property="deleteYn" column="DELETE_YN"/> <result property="regiDt" column="REGI_DT"/> <result property="regiUser" column="REGI_USER"/> <result property="modiDt" column="MODI_DT"/> <result property="modiUser" column="MODI_USER"/> </resultMap> <select id="selectBoardListCnt" resultClass="int"> SELECT COUNT(*) AS CNT FROM BOARD </select> <select id="selectBoardList" parameterClass="map" resultMap="r_boardVo"> <![CDATA[ SELECT * FROM ( SELECT PP.*, ROWNUM PPRN FROM ( SELECT BOARD_SEQ, BOARD_TYPE, STEP, TITLE, CONTENT, IP, DELETE_YN, TO_CHAR(REGI_DT, 'YYYY-MM-DD') AS REGI_DT, REGI_USER, TO_CHAR(MODI_DT, 'YYYY-MM-DD') AS MODI_DT, MODI_USER FROM BOARD WHERE DELETE_YN = 'N' ORDER BY BOARD_SEQ DESC ) PP WHERE ROWNUM < #endRowNo# ) WHERE PPRN > #beginRowNo# ]]> </select> <select id="selectBoardDetail" parameterClass="int" resultMap="r_boardVo"> SELECT BOARD_SEQ, BOARD_TYPE, STEP, TITLE, CONTENT, IP, DELETE_YN, TO_CHAR(REGI_DT, 'YYYY-MM-DD') AS REGI_DT, REGI_USER, TO_CHAR(MODI_DT, 'YYYY-MM-DD') AS MODI_DT, MODI_USER FROM BOARD WHERE BOARD_SEQ = #value# </select> <parameterMap id="p_boardVo" class="source.board.vo.BoardVO"> <parameter property="title"/> <parameter property="content" jdbcType="CLOB"/> <parameter property="ip"/> <parameter property="boardSeq"/> </parameterMap> <update id="update" parameterMap="p_boardVo"> UPDATE BOARD SET TITLE = ?, CONTENT = ?, IP = ?, MODI_DT = SYSDATE, MODI_USER = 'SUN' WHERE BOARD_SEQ = ? </update> <update id="deleteBoard" parameterClass="int"> UPDATE BOARD SET DELETE_YN = 'Y' WHERE BOARD_SEQ = #value# </update> <select id="selectBoardSeq" resultClass="int"> SELECT BOARD_SEQ.NEXTVAL FROM DUAL </select> <parameterMap id="p_in_boardVo" class="source.board.vo.BoardVO"> <parameter property="boardSeq"/> <parameter property="boardType"/> <parameter property="step"/> <parameter property="title"/> <parameter property="content" jdbcType="CLOB"/> <parameter property="ip"/> </parameterMap> <insert id="insertBoard" parameterMap="p_in_boardVo"> INSERT INTO BOARD(BOARD_SEQ, BOARD_TYPE, STEP, TITLE, CONTENT, IP, DELETE_YN, REGI_DT, REGI_USER, MODI_DT, MODI_USER) VALUES(?, ?, ?, ?, ?, ?, 'N', SYSDATE, 'ADMIN', SYSDATE, 'ADMIN') </insert> </sqlMap> |
===============================================================================================================
boardList.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@page import="source.util.PageNavigation"%> <html> <head> <title>Board List</title> <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("tr:even").css("background-color", "bbbbff"); $("tr:first").css("background-color", "red"); }); function goDetail(board_seq){ var doc = document.boardForm; doc.method="post"; doc.boardSeq.value = board_seq; doc.act.value = "d"; doc.action = "boardDetail.sn"; doc.submit(); } function goInsert(){ var doc = document.boardForm; doc.act.value = "movePage"; doc.action = "boardInsert.sn"; doc.submit(); } </script> </head> <% PageNavigation pageNavigation = (PageNavigation)request.getAttribute("pageNavigation"); %> <body> <form name="boardForm" action="boardDetail.sn" method="post"> <input type="hidden" name="boardSeq" value=""/> <input type="hidden" name="act" value=""/> <input type="hidden" name="pageNo" value="<%=pageNavigation.getCurrentPageNo()%>"/> <table border="1" align="center"> <tr> <th width="50">No.</th> <th width="400">제목</th> <th width="100">등록일</th> <th width="100">등록자</th> </tr> <c:forEach items="${boardList}" var="board"> <tr> <td align="center"> <c:out value="${board.boardSeq}"></c:out> </td> <td align="left" style="cursor: pointer;" onclick="goDetail('<c:out value="${board.boardSeq}"></c:out>')"> <c:out value="${board.title}"></c:out> </td> <td align="center"> <c:out value="${board.regiDt}"></c:out> </td> <td align="center"> <c:out value="${board.regiUser}"></c:out> </td> </tr> </c:forEach> </table> </form> <div id='navigation' align="center"> <% out.println(pageNavigation.getNavigationStr()); out.println(pageNavigation.getMakeParamForm()); %> </div> <input type="button" name="insert" value="INSERT" onclick="goInsert()"/> </body> </html> |
boardDetail.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>BOARD LIST</title> <script type="text/javascript"> function goList(){ var frm = document.detailForm; frm.action = "boardList.sn"; frm.submit(); } function goModify(){ var frm = document.detailForm; frm.action = "boardDetail.sn"; frm.act.value = "u"; frm.submit(); } function goDelete(){ var frm = document.detailForm; frm.action = "boardDelete.sn"; frm.submit(); } </script> </head> <body> <form name="detailForm" method="post"> <input type="hidden" name="boardSeq" value="<c:out value="${boardDetail.boardSeq}"></c:out>"/> <input type="hidden" name="act" value=""/> <input type="hidden" name="pageNo" value="<%=request.getParameter("pageNo")%>"/> <table border="1"> <tr> <td>Title</td> <td colspan="3"> <c:out value="${boardDetail.title}"></c:out> </td> </tr> <tr> <td>작성자</td> <td> <c:out value="${boardDetail.regiUser}"></c:out> </td> <td>등록일</td> <td><c:out value="${boardDetail.regiDt}"></c:out> </td> </tr> <tr> <td colspan="4"> <textarea rows="20" cols="80"><c:out value="${boardDetail.content}"></c:out></textarea> </td> </tr> </table> <p></p> <input type="button" name="modify" value="MODIFY" onclick="goModify()"/> <input type="button" name="delete" value="DELETE" onclick="goDelete()"/> <input type="button" name="list" value="LIST" onclick="goList()"/> </form> </body> </html> |
boardModify.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>게시물 수정</title> <link href="se/css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="se/js/HuskyEZCreator.js" charset="utf-8"></script> </head> <body> <form name="modifyForm" action="boardUpdate.sn" method="post"> <input type="hidden" name="boardSeq" value="<c:out value="${boardDetail.boardSeq}"/>"/> <input type="hidden" name="boardType" value="<c:out value="${boardDetail.boardType}"/>"/> <input type="hidden" name="pageNo" value="<%=request.getParameter("pageNo")%>"/> <table border="1"> <tr> <td>Title</td> <td colspan="3"><input type="text" name="title" value="<c:out value="${boardDetail.title}"/>"/> </td> </tr> <tr> <td>작성자</td> <td><input type="text" name="regiUser" value="<c:out value="${boardDetail.regiUser}"/>" style="border: 0" readonly="readonly"/> </td> <td>등록일</td> <td><c:out value="${boardDetail.regiDt}"></c:out> </td> </tr> <tr> <td colspan="4"> <textarea name="ir1" id="ir1" style="width:500px; height:300px; display:none;"><c:out value="${boardDetail.content}"/></textarea> </td> </tr> </table> <p> <input type="button" name="list" value="List" onclick="goList();"/> <input type="button" name="modify" value="Update" onclick="_onSubmit(this);"/> </p> </form> <script> var oEditors = []; nhn.husky.EZCreator.createInIFrame({ oAppRef: oEditors, elPlaceHolder: "ir1", sSkinURI: "se/SEditorSkin.html", fCreator: "createSEditorInIFrame" }); function _onSubmit(elClicked){ // 에디터의 내용을 에디터 생성시에 사용했던 textarea에 넣어 줍니다. oEditors.getById["ir1"].exec("UPDATE_IR_FIELD", []); // 에디터의 내용에 대한 값 검증은 이곳에서 document.getElementById("ir1").value를 이용해서 처리하면 됩니다. var contentTxt = document.getElementById("ir1").value; if(contentTxt == null || contentTxt == ''){ alert('empty content'); return; } try{ elClicked.form.submit(); }catch(e){} } function goList(){ var doc = document.modifyForm; doc.action = "boardList.sn"; doc.submit(); } </script> </body> </html> |
boardInsert.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>게시물 작성</title> <link href="se/css/default.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="se/js/HuskyEZCreator.js" charset="utf-8"></script> </head> <body> <form name="insertForm" action="boardInsert.sn" method="post"> <input type="hidden" name="act" value="insert"/> <input type="hidden" name="pageNo" value="1"/> <table border="1"> <tr> <td>Title</td> <td colspan="3"><input type="text" name="title" value=""/> </td> </tr> <tr> <td>작성자</td> <td><input type="text" name="regiUser" value=""/> </td> <td>등록일</td> <td><c:out value="${boardDetail.regiDt}"></c:out> </td> </tr> <tr> <td colspan="4"> <textarea name="ir1" id="ir1" style="width:500px; height:300px; display:none;"></textarea> </td> </tr> </table> <p> <input type="button" name="list" value="List" onclick="goList();"/> <input type="button" name="save" value="Save" onclick="_onSubmit(this);"/> </p> </form> <script> var oEditors = []; nhn.husky.EZCreator.createInIFrame({ oAppRef: oEditors, elPlaceHolder: "ir1", sSkinURI: "se/SEditorSkin.html", fCreator: "createSEditorInIFrame" }); function _onSubmit(elClicked){ // 에디터의 내용을 에디터 생성시에 사용했던 textarea에 넣어 줍니다. oEditors.getById["ir1"].exec("UPDATE_IR_FIELD", []); // 에디터의 내용에 대한 값 검증은 이곳에서 document.getElementById("ir1").value를 이용해서 처리하면 됩니다. var contentTxt = document.getElementById("ir1").value; if(contentTxt == null || contentTxt == ''){ alert('empty content'); return; } try{ elClicked.form.submit(); }catch(e){} } function goList(){ var doc = document.insertForm; doc.action = "boardList.sn"; doc.submit(); } </script> </body> </html> |
boardList.jsp 화면
boardDetail.jsp 화면
boardModify.jsp 화면
boardInsert.jsp 화면
'프로그램 > Spring 2.5' 카테고리의 다른 글
ParameterizableViewController와 UrlFilenameViewController (0) | 2012.03.07 |
---|---|
Spring Controller의 종류 (0) | 2012.03.07 |
[21일차] spring MVC 예제 - 4 (MultiActionController) (0) | 2012.02.29 |
[링크] ModelAndView에서 파라미터 전달 (0) | 2012.02.28 |
[20일차] spring MVC 예제 - 3 (SimpleFormController) (0) | 2012.02.18 |