본문 바로가기
매일코딩/Spring

30.스프링프로젝트 - 답변

by 인생여희 2016. 11. 21.
반응형





maper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
-- list - det gul
 
 
select idx, b.userid,name,subject,hit,post_date,filename,filesize, (select count(*
 from board_comment
 where board_idx=b.idx) comment_count,b.ref,b.reorder,b.depth
from board b,member m 
where b.userid=m.userid 
order by b.ref desc, b.reorder asc limit 0,10;
 
 
 
update board set reorder=reorder+1
where ref=1
and reorder > 0;
        
        
        
        
        insert into board( userid, subject,content, ref,
        depth, reorder)
        values(
        'kim',
        'jemok',
        'content',103
 
        );
        
        commit;
cs



viw.jsp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%-- <%@ page session="false"%> --%>
<c:set var="path" value="${pageContext.request.contextPath}"></c:set> 
 
 
<jsp:include page="boardHeader.jsp" flush="false"/>
 
 
                    <h1 id="product"><div>COMMUNITY</div></h1>
          <article>
              <h2>게시판</h2>
              
    <!-- 개발 경로가 아닌 실제 경로 -->
    <%-- <%=application.getRealPath("/upload")%> --%>
 
 
    <form name="form1" method="post" enctype="multipart/form-data">
        <table border="1" width="650px" align="center" >
 
 
 
            <tr>
                <td align="center">날짜</td>
                <td align="center">${dto.post_date}</td>
                <td align="center">조회수</td>
                <td align="center">${dto.hit}</td>
            </tr>
 
            <tr>
                <td align="center">제목</td>
                <td colspan="3"><input name="subject" size="80"
                    value="${dto.subject}"></td>
            </tr>
            <tr>
                <td align="center">내용</td>
                <td colspan="3"><textarea rows="5" cols="80" name="content"
                        id="content">${dto.content}</textarea>
                        
                        
                         <script>
                            //textarea의 id값과 일치해야함//textarea의 id값과 일치해야함
                            CKEDITOR
                                    .replace(
                                            'content',
                                            {
                                                filebrowserUploadUrl : '${pageContext.request.contextPath}/imageUpload.do'
 
                                            });
                        </script>
                        
                        
                        </td>
            <tr>
                <td align="center">첨부파일</td>
                <td colspan="3" width='30'>
                <c:if test="${dto.filesize>0 }">
                ${dto.filename} (${dto.filesize} bytes)
                <br>
                
                <input type="checkbox" name="fileDel">첨부파일 삭제
                
                </c:if>
                
                <input type="file" name="file1"></td>
 
            </tr>
 
 
 
 
            <tr>
                <td colspan="4" align="center">
                
                
                <!-- 로그인 했을때 답변달 수있게 했음 -->    
                <c:if test="${sessionScope.id != null}">
                <input type="button" value="답변" id="btnReply">
                </c:if>
            
            
                 <!-- 본인글만 수정/삭제가 가능하도록 처리 -->
                <c:if test="${sessionScope.id==dto.userid }">
                        <input type="button" value="수정" id="btnUpdate">
                        <input type="button" value="삭제" id="btnDelete">
                        <input type="button" value="목록" id="btnList">
                </c:if>
            
            
                </td>
            
            
            </tr>
        </table>
    </form>
 
 
 <!-- 답변글 작성을 위해 게시물 번호를 넘겨야함 -->
<input type="hidden" name="idx" id="idx" value="${dto.idx}">
 
    <!-- 댓글 작성폼(로그인한 사용자만 댓글 달기 허용) -->
 
 
    <div align="center" >
    
        <!-- if user is not null  only login-->
        <c:if test="${sessionScope.id != null }">
 
            <table style="width: 650px;" class="tbl_type">
                
<br>
                <font size="4" style="text-decoration : underline ;"><B>댓글달기</B></font>
                
      
        <br>
                
                <tr>
                <br>
                    <td ><textarea rows="3" cols="81" id="comment_content"></textarea></td>
                    <td><input type="button" style="width:40pt;height:40pt;" value="댓글" id="btnSave"></td>
                </tr>
            </table>
        </c:if>
    </div>
 
    <div id="commentList" align="center"></div>
 
 
    </article>
          <jsp:include page="boardSidebar.jsp" flush="false"/>
 
          <jsp:include page="boardFooter.jsp" flush="false"/>
cs



viwheader.jsp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
   <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 
<c:set var="path" value="${pageContext.request.contextPath}"></c:set> 
    
<html>
<head>
<meta charset="utf-8">
<title>Company</title>
 
<link href="../resources/css/reset.css" rel="stylesheet" type="text/css">
 
<link href="../resources/css/jquery.fancybox.css" rel="stylesheet" type="text/css">
 
 
<link href='http://fonts.googleapis.com/css?family=Droid+Sans'
    rel='stylesheet' type='text/css'>
    
    
    <style>
/* UI Object */
.tbl_type,.tbl_type th,.tbl_type td{border:0}
.tbl_type{width:75%;border-bottom:2px solid #dcdcdc;font-family:'돋움',dotum;font-size:12px;text-align:center;border-collapse:collapse}
.tbl_type caption{display:none}
.tbl_type tfoot{background-color:#f5f7f9;font-weight:bold}
.tbl_type th{padding:7px 4px;border-top:2px solid #dcdcdc;border-right:1px solid #dcdcdc;border-left:1px solid #dcdcdc;background-color:#f5f7f9;color:#666;font-family:'돋움',dotum;font-size:12px;font-weight:bold}
.tbl_type td{padding:6px 4px;border:1px solid #e5e5e5;color:#4c4c4c}
.tbl_type td.ranking{font-weight:bold}
/* //UI Object */
</style>
    
    <script src="http://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript">
    $(document).ready(
            function() { //웹페이지가 로딩되면
 
                comment_list('1'); //댓글 목록 가져오기
 
                //수정 버튼 클릭
                
                 $("#btnUpdate").click(function(){
                     
                     document.form1.action="${path}/board/board_update.do?idx="+$("#idx").val();
                         
                         /* ?idx="+$("#idx").val()
                             +"?subject="+$("#subject").val()+"?filename="+$("#filename").val()
                             +"?filesize="+$("#filesize").val()+"?content="+$(content).val(); */
                     document.form1.submit();
                 })
                
                
                
                 //글쓰기 버튼 클릭
                $("#btnWrite").click(function(){
                    location.href="${path}/board/write.do";
                });
                 
                 
                //목록 버튼 클릭
                $("#btnList").click(function(){
                    location.href="${path}/board/board_list.do";
                });
 
                //답변 버튼 클릭
                
                $("#btnReply").click(function(){
                
                    document.form1.action="${path}/board/board_reply.do?idx="+$("#idx").val();
                    document.form1.submit();
                });
                
                //삭제 버튼 클릭
                
                $("#btnDelete").click(function(){
                    
                    if(confirm("삭제하시겠습니까?")){
                        document.form1.action ="${path}/board/board_delete.do?idx="+$("#idx").val();
                        document.form1.submit();
                    }
                
                });
                
                
                
                
                
                $("#btnSave").click(
                        function() {//버튼 클릭 이벤트 등록
 
                            var param = "board_idx=${dto.idx}&content="
                                    + $("#comment_content").val();
                            //비동기 방식으로 댓글 쓰기, 결과값은 json 형식으로 리턴받음
 
                            $.ajax({
                                type : "post",
                                
                                /*  if this is empty..defalut type is html */
                                contentType : "application/json",
                                url : "${path}/board/comment_insert.do?"+param,
                                success : function() {
                                    
                                    //댓글쓰기가 완료되면 댓글 목록 갱신
                                    comment_list('1');
                                    
                                    //댓글 입력 텍스트상자 초기화
                                    $("#comment_content").val("");
                                }
 
                            });
 
                        });
            });
 
    //댓글 목록 가져오기
    function comment_list(page) {
 
        $.ajax({
            type : "post",
            contentType : "application/json",
            url : "${path}/board/comment_list.do?board_idx=${dto.idx}&curPage="+page,
            success : function(data) {
 
                /* var output = "<table width='800px' border='1'>";
                for ( var i in json) {
                    output += "<tr>";
                    output += "<td>" + json[i].post_date + "</td>";
                    output += "<td>" + json[i].content + "</td>";
                    output += "</tr>";
                }
                output += "</table>"; */
 
                $("#commentList").html(data);
            }
 
        });
 
    }
</script>
 
<script type="text/javascript" src="${path}/ckeditor/ckeditor.js"></script>
    
</head>
 
 
 
 
<body>
        <div id="wrap">
            
            <!-- 헤더부분 -->
            
            <header>
                <div id="logo"><a href="${pageContext.request.contextPath}/main/main.html">YNG Corp.</a> </div>
                <div id="hlink">
                    <ul>
                                    <c:choose>
                        <c:when test="${sessionScope.id==null }">
                            <!-- 세션변수 id 값이 없을때 -->
                            <li><a href="${path}/member/login">로그인·회원가입</a></li>
                        <!--     <li><a href="/web03/member/memberInsert">회원가입</a></li> -->
                        </c:when>
 
                        <c:otherwise>
                            <!-- 세션 변수 id 값이 있을때 -->
        
    [  ${sessionScope.name}님 로그인 중 ]
    <li><a href="${path}/member/logout">로그아웃</a></li>
    
                            <%-- <a href="${path}/pdf/pdf_save.do">pdf문서생성</a>
                            <a href="${path}/chart/chart1.do">차트보기</a> --%>
                            <%-- <li><a href="${path}/member/member_info.do">회원정보 수정</a></li> --%>
                        </c:otherwise>
 
                    </c:choose>
                    
                    </ul>
                </div>
                
                <nav>
                    <ul>
                        <li class="n1"><a href="${pageContext.request.contextPath}/company/company.html">회사소개</a></li>                    
                        <li class="n2"><a href="${pageContext.request.contextPath}/product/product.html">제품정보</a></li>
                        <li class="n3"><a href="${pageContext.request.contextPath}/board/board_list.do">커뮤니티</a></li>
                        <li class="n4"><a href="${pageContext.request.contextPath}/mail/mail_form.do">고객지원</a></li>
                    </ul>
                </nav>
            </header>    
cs


boardcontroller.jsp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    // 답변달기
    @RequestMapping("board/board_reply.do")
    public String board_reply(@RequestParam int idx, Model model) {
        BoardDTO dto = boardService.boardView(idx);
        
        String content = "================게시물의 내용================/n";
 
        dto.setContent(content + dto.getContent());
        model.addAttribute("dto", dto); // 모델에 저장
 
        // board/board_reply 로 포워딩
 
        return "board/board_reply";
    }
 
    // 답변글 입력하기
 
    @RequestMapping("board/reply_insert.do")
 
    public String reply_insert(@RequestParam int idx, @RequestParam String subject, @RequestParam String content,
            HttpSession session) {
 
        BoardDTO dto = boardService.boardView(idx);
        int ref = dto.getRef(); // 게시물그룹 번호
        int depth = dto.getDepth() + 1// 답변 단계
        int reorder = dto.getReorder() + 1// 같은 그룹 내에서의 순서
 
        String id = (String) session.getAttribute("id"); // 사용자 아이디
 
        // 게시물 그룹 내에서의 순서 조정
        boardService.reorderUpdate(ref, reorder);
 
        // 테이블에 저장
 
        dto = new BoardDTO();
        dto.setUserid(id);
        dto.setSubject(subject);
        dto.setContent(content);
        dto.setRef(ref);
        dto.setDepth(depth);
        dto.setReorder(reorder);
 
        boardService.replyInsert(dto);
        return "redirect:/board/board_list.do";
    }
cs



boardreply.jsp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
    // 답변달기
    @RequestMapping("board/board_reply.do")
    public String board_reply(@RequestParam int idx, Model model) {
        BoardDTO dto = boardService.boardView(idx);
        
        String content = "================게시물의 내용================/n";
 
        dto.setContent(content + dto.getContent());
        model.addAttribute("dto", dto); // 모델에 저장
 
        // board/board_reply 로 포워딩
 
        return "board/board_reply";
    }
 
    // 답변글 입력하기
 
    @RequestMapping("board/reply_insert.do")
 
    public String reply_insert(@RequestParam int idx, @RequestParam String subject, @RequestParam String content,
            HttpSession session) {
 
        BoardDTO dto = boardService.boardView(idx);
        int ref = dto.getRef(); // 게시물그룹 번호
        int depth = dto.getDepth() + 1// 답변 단계
        int reorder = dto.getReorder() + 1// 같은 그룹 내에서의 순서
 
        String id = (String) session.getAttribute("id"); // 사용자 아이디
 
        // 게시물 그룹 내에서의 순서 조정
        boardService.reorderUpdate(ref, reorder);
 
        // 테이블에 저장
 
        dto = new BoardDTO();
        dto.setUserid(id);
        dto.setSubject(subject);
        dto.setContent(content);
        dto.setRef(ref);
        dto.setDepth(depth);
        dto.setReorder(reorder);
 
        boardService.replyInsert(dto);
        return "redirect:/board/board_list.do";
    }
cs



boardDAOImpl.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
@Override
    public void reorderUpdate(int ref, int reorder) {
 
        try {
 
            Map<String, Object> map = new HashMap<String, Object>();
 
            map.put("ref", ref);// 게시물 그룹 번호
            map.put("reorder", reorder); // 같은 게시물 그룹 내에서의 순서
            sqlSession.update("reorderUpdate", map);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
 
    }
 
    @Override
    public void replyInsert(BoardDTO dto) {
 
        try {
 
            sqlSession.insert("replyInsert", dto);
 
        } catch (Exception e) {
 
            e.printStackTrace();
        }
 
    }
cs



boardList.jsp


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%-- <%@ page session="false"%> --%>
<c:set var="path" value="${pageContext.request.contextPath}"></c:set> 
 
 
 
 
<jsp:include page="boardHeader.jsp" flush="false"/>
 
 
                    <h1 id="community"><div>COMMUNITY</div></h1>
          <article>
              <h2>게시판</h2>
              
 
    
    <table border="1" align="center" class="tbl_type" WIDTH=50% table-layout: fixed>
        <tr>
            <th  nowrap WIDTH="40">번호</th>
            <th  nowrap WIDTH="100">이름</th>
            <th  nowrap WIDTH="250">제목</th>
            <th  nowrap WIDTH="100">날짜</th>
            <th  nowrap WIDTH="40">조회</th>
            <th  nowrap WIDTH="70">첨부파일</th>
            <th  nowrap WIDTH="70">다운로드</th>
        </tr>
 
 
        <c:forEach var="row" items="${list}">
            <tr>
                <td>${row.idx }</td>
                <td>${row.username }</td>
                <td>
                
                <!-- 답변 들여쓰기 -->
                <c:forEach begin="1" end="${row.depth }">
                &nbsp;&nbsp;
                </c:forEach>
    
    
 
                <a href="${path}/board/view.do?idx=${row.idx}">
                ${row.subject}</a>
                <c:if test="${row.comment_count >0 }">
            
            <span style="color:red">[${row.comment_count}]</span>
                
                </c:if>
                </td>
    
                <td>${row.post_date}</td>
                <td>${row.hit}</td>
                
                
                <!-- 첨부파일의 사이즈가 보다 크면 파일 다운로드 링크 표시 -->
                
                
                <td align="center">
                <c:if test="${row.filesize > 0 }">
                    <a href="${path}/board/down.do?idx=${row.idx}">
                    <img src="${path}/images/file.gif">
                </a>
                </c:if>
                </td>
 
                <td>${row.down}</td>
            </tr>
        </c:forEach>
 
 
<!-- page navigation -->
<tr align="center">
<td colspan="7">
<!-- 이전 -->
<c:if test="${page.curPage>1 }">
<a href="${path}/board/board_list.do?curPage=1&search_option=${search_option}&search=${search}">[시작] </a>
</c:if>
 
<c:if test="${page.curBlock > 1 }">
<a href="${path}/board/board_list.do?curPage=${page.prevPage}&search_option=${search_option}&search=${search}">[이전] </a>
</c:if>
 
 
 
<c:forEach var="pageNum" begin="${page.blockStart}" end="${page.blockEnd}">
 
<c:choose>
    <c:when test="${pageNum==page.curPage }">
 
    <span style="color:red">[${pageNum}]</span>
    </c:when>
    
    <c:otherwise>
<a href="${path}/board/board_list.do?curPage=${pageNum}&search_option=${search_option}&search=${search}">[${pageNum}] </a>&nbsp;
    </c:otherwise>
</c:choose>
 
</c:forEach>
 
<!-- 다음 -->
 
 
<c:if test="${page.curBlock <= page.totBlock}">
 
<a href="${path}/board/board_list.do?curPage=${page.nextPage}&search_option=${search_option}&search=${search}">[다음] </a>
</c:if>
 
<!-- 마지막 페이지 -->
 
<c:if test="${page.curPage < page.totPage}">
 
<a href="${path}/board/board_list.do?curPage=${page.totPage}&search_option=${search_option}&search=${search}">[끝] </a>
 
</c:if>
</td>
 
</tr>
 
    </table>
 
<br>
<!-- 검색폼 -->
 
    <form method="post" action="${path}/board/board_list.do">
        <div align="center"><select name="search_option">
            <option value="username"
            
            <c:if test= "${search_option =='username'}"> selected </c:if> >
            이름
            </option>
            
            <option value="subject" <c:if test= "${search_option =='subject'}"> selected </c:if> >제목</option>
            <option value="content" <c:if test= "${search_option =='content'}"> selected </c:if> >내용</option>
            <option value="all" <c:if test= "${search_option =='all'}"> selected </c:if> >전체</option>
        </select>
        
        <input type="text" name="search" value="${search}">
        <input type="submit" value="확인">&nbsp;&nbsp;&nbsp;
        <input type="button" id="btnWrite" value="글쓰기"></div>
    </form>    
 
    </article>
          <jsp:include page="boardSidebar.jsp" flush="false"/>
 
          <jsp:include page="boardFooter.jsp" flush="false"/>
 
cs



<insert id="replyInsert">


insert into board(idx, userid, subject,content, ref,

depth, reorder)

values(

(select nvl(max(idx)+1,1) from

board),#{userid},

#{subject},

#{content},#{ref}, #{depth}, #{reorder}


)

</insert>


<update id="reorderUpdate">


update board set reorder=reorder+1

where ref=#{ref}

and reorder > #{reorder}

</update>

반응형

'매일코딩 > Spring' 카테고리의 다른 글

스프링 기초 DI 예제1  (0) 2018.07.16
31.스프링프로젝트 - 조회  (4) 2016.11.21
29.spring- detgul  (2) 2016.11.18
28.spring - hitup  (4) 2016.11.18
27.springproject - log  (4) 2016.11.18

댓글