1. VO 에 ref,  seq,  lvl 추가

2. getList.jsp에서
    <s:iterator value="list">
                <s:url action="reply" id="goReply">
                    <s:param name="ref" value="ref"/>
                    <s:param name="seq" value="seq"/>
                    <s:param name="lvl" value="lvl"/>
                </s:url>
                <s:a href="%{goReply}">
                    <tr>
                        <td><s:property value="idx"/></td>
                        <td>
                            <c:forEach begin="1" end="${lvl}"step="1">
                                &nbsp;&nbsp;&nbsp;
                            </c:forEach>
                            <s:if test="%{lvl > 0}">
                                <img src="images/reply.gif" border="0"/>
                            </s:if>
                        <s:property value="subject"/></td>
                        <td><s:property value="writer"/></td>
                        <td><s:property value="regdate"/></td>
                        <td><s:property value="hit"/></td>
                    </tr>
                </s:a>
            </s:iterator>
--상세정보로 들어갈때  파라미터 ref, seq, lvl의 값을 가지고 감

3. 답글 쓸때
Info에서 답글버튼을 누르면   private int ref,  seq,  lvl;  값을 가지고 입력 폼으로 이동
<s:form action="replyInsert" theme="simple" method="post">
            작성자 : <s:textfield name="writer"/><br/>
            비밀번호 : <s:password name="pwd"/><br/>
            제  목 : <s:textfield name="subject"/><br/>
            <s:textarea theme="simple" cols="70" rows="10" name="content"/><br/>
            <s:hidden name="ref" value="%{ref}"/>            //<--본문글번호
            <s:hidden name="seq" value="%{seq+1}"/>      //몇번째 recomment인지
            <s:hidden name="lvl" value="%{lvl+1}"/>           //depth
            <s:submit value="글쓰기"/>
        </s:form>

4. 답글 저장
public boolean replyInsert(BoardVO board) {
        SqlMapClient sqlMap = null;
        try {
            sqlMap = SqlMapUtil.getSqlMap();
            sqlMap.startTransaction();
            sqlMap.update("replyUpdate_board", board);               
            sqlMap.insert("replyInsert_board", board);
            sqlMap.commitTransaction();
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        } finally {
            try {
                sqlMap.endTransaction();
            } catch (SQLException sQLException) {
            }
        }
    }

4-1. query

 <insert id="insert_board" parameterClass="board">
        <selectKey keyProperty="idx" resultClass="int">      
         //<--lvl 0 글입력시 ref에 들어갈 값은 idx와 같기 때문에 selectKey이용
            SELECT board_seq.nextval FROM dual
        </selectKey>
        INSERT INTO board VALUES(#idx#, #pwd#,#writer#,#subject#,#content#,sysdate,0,#idx#,1,0)
    </insert>

<update id="replyUpdate_board" parameterClass="board">
        <![CDATA[ UPDATE board SET seq = seq+1 WHERE ref=#ref# AND seq >= #seq# ]]>
    </update>

 <insert id="replyInsert_board" parameterClass="board">
        INSERT INTO board VALUES(board_seq.nextval,#pwd#,#writer#,#subject#,#content#,sysdate,0,#ref#,#seq#,#lvl#)
    </insert>

5. list출력시
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  <td>
                            <c:forEach begin="1" end="${lvl}"step="1">
                                &nbsp;&nbsp;&nbsp;
                            </c:forEach>
                            <s:if test="%{lvl > 0}">
                                <img src="images/reply.gif" border="0"/>
                            </s:if>
                        <s:property value="subject"/></td>


신고

'programing > JAVA' 카테고리의 다른 글

HTML A태그, IMG태그 추출  (1) 2009.06.22
HTML 태그제거 소스  (0) 2009.06.22
계층형 게시판  (0) 2009.06.03
File Up & Down  (0) 2009.06.02
Paging  (0) 2009.06.02
FileUtil  (0) 2009.06.02
Posted by 대절님

댓글을 달아 주세요



티스토리 툴바