자바/스프링

[Spring] 게시판 답변 BoardReply

SimpleU 2020. 3. 13. 21:00

1 ) 게시판 답변 Controller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
    //게시판 게시글 답변
    @RequestMapping(value = "/boardReply")
    public String boardReply(HttpServletRequest request, HttpServletResponse response) throws Exception {
 
        return "board/boardReply";
    }
 
 
    @RequestMapping(value = "/insertBoardReply")
    @ResponseBody
    public BoardDto insertBoardReply(HttpServletRequest request, HttpServletResponse response, BoardForm boardForm) throws Exception {
 
        MDC.put("TRANSACTION_ID"String.valueOf(boardForm.getBoard_seq()));
        
        BoardDto boardDto = boardService.insertBoardReply(boardForm);
        
        MDC.remove("TRANSACTION_ID");
 
        return boardDto;
    }
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

@RequestMapping - 요청 URL을 어떤 메소드가 처리할 지 여부를 결정

@ResponseBody - 자바 객체를 HTTP 응답 몸체로 전송함

                       - 자바 객체를 HTTP 요청의 body 내용으로 매핑하는 역할

MDC - 웹 요청에 대한 로그인 정보나 세션 정보를 추적할 수 있기 때문에 설정함

       - 이 소스코드는 로그인 정보나 세션 정보가 없기 때문에 board_seq값을 추가 함

 

2 ) 게시판 답변 Dao

1
2
3
4
5
6
7
8
9
    public BoardDto getBoardReplyInfo(BoardForm boardForm) throws Exception {
        return sqlSession.selectOne(NAMESPACE + ".getBoardReplyInfo", boardForm);
    }
 
    public int insertBoardReply(BoardForm boardForm) throws Exception {
        return sqlSession.insert(NAMESPACE + ".insertBoardReply", boardForm);
    }
 

 

3 ) 게시판 답변 Dto getter / setter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    int board_seq; // 게시글 번호
    int board_re_ref; // 게시글 그룹 번호
    int board_re_lev; // 게시글 글의 깊이
    int board_re_seq; // 게시글 글의 순서
    String board_writer; // 작성자
    String board_subject; // 제목
    String board_content; // 내용
    int board_hits; // 조회수
    String del_yn; // 삭제유무
    String ins_user_id; // Insert 사용자 아이디
    String ins_date; // Insert 날짜
    String upd_user_id; // Update 사용자 아이디
    String upd_date; // Update 날짜
    String result;
 

 

4 ) 게시판 답변 Service

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
    /* 게시판 게시글 답변 */
    public BoardDto insertBoardReply(BoardForm boardForm) throws Exception {
 
        BoardDto boardDto = new BoardDto();
 
        BoardDto boardReplayInfo = boardDao.getBoardReplyInfo(boardForm);
 
        boardForm.setBoard_seq(boardReplayInfo.getBoard_seq());
        boardForm.setBoard_re_lev(boardReplayInfo.getBoard_re_lev());
        boardForm.setBoard_re_ref(boardReplayInfo.getBoard_re_ref());
        boardForm.setBoard_re_seq(boardReplayInfo.getBoard_re_seq());
 
        int insertCnt = 0;
 
        insertCnt += boardDao.updateBoardReSeq(boardForm);
 
        insertCnt += boardDao.insertBoardReply(boardForm);
 
        if (insertCnt > 0) {
            boardDto.setResult("SUCCESS");
        } else {
            boardDto.setResult("FAIL");
        }
 
        return boardDto;
    }
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

5 ) 게시판 답변 mapper

- 게시글 답글 정보 조회 ( getBoardReplyInfo )

- 게시글 답글 순서 수정 ( updateBoardReSeq )

- 게시글 답글 등록 ( insertBoardReply ) 

 

6 ) 게시판 답변 view boardReply

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
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>게시판 답글</title>
<%    
    String boardSeq = request.getParameter("boardSeq");        
%>
 
<c:set var="boardSeq" value="<%=boardSeq%>"/> <!-- 게시글 번호 -->
 
<!-- 공통 CSS -->
<link rel="stylesheet" type="text/css" href="/css/common/common.css"/>
 
<!-- 공통 JavaScript -->
<script type="text/javascript" src="/js/common/jquery.js"></script>
<script type="text/javascript">
    
    //자바스크립트의 onclick 같은 기능 html이 화면에 뿌려지고 나서 ready안에 서술된 이벤트들이 동작 준비를 하는 것
    $(document).ready(function(){        });
        
    /** 게시판 - 목록 페이지 이동 */
    function goBoardList(){                
        location.href = "/board/boardList";
    }
    
    /** 게시판 - 답글 작성  */
    function insertBoardReply(){
       //양식의 값을 가져오거나 값을 설정하는 메소드
        var boardSubject = $("#board_subject").val();
        var boardContent = $("#board_content").val();
            
        if (boardSubject == ""){            
            alert("제목을 입력해주세요.");
            $("#board_subject").focus();
            return;
        }
        
        if (boardContent == ""){            
            alert("내용을 입력해주세요.");
            $("#board_content").focus();
            return;
        }
        
        var yn = confirm("게시글을 등록하시겠습니까?");        
        if(yn){
                
            $.ajax({    
                
                url        : "/board/insertBoardReply",
                //serialize - 데이터를 보내기위해 form요소를 문자열로 인코딩
                data    : $("#boardForm").serialize(),
                dataType: "JSON",
                cache   : false,
                async   : true,
                type    : "POST",    
                success : function(obj) {
                    insertBoardReplyCallback(obj);                
                },           
                error     : function(xhr, status, error) {}
                
            });
        }
    }
    
    /** 게시판 - 작성 콜백 함수 */
    function insertBoardReplyCallback(obj){
    
        if(obj != null){        
            
            var result = obj.result;
            
            if(result == "SUCCESS"){                
                alert("게시글 답글 등록을 성공하였습니다.");                
                goBoardList();                 
            } else {                
                alert("게시글 답글 등록을 실패하였습니다.");    
                return;
            }
        }
    }
    
</script>
</head>
<body>
<div id="wrap">
    <div id="container">
        <div class="inner">        
            <h2>게시글 작성</h2>
            <form id="boardForm" name="boardForm">
                <input type="hidden" id="board_parent_seq"    name="board_parent_seq"    value="${boardSeq}"/> <!-- 부모 게시글 번호 -->
                <table width="100%" class="table02">
                <caption><strong><span class="t_red">*</span> 표시는 필수입력 항목입니다.</strong></caption>
                    <colgroup>
                        <col width="20%">
                        <col width="*">
                    </colgroup>
                    <tbody id="tbody">
                        <tr>
                            <th>제목<span class="t_red">*</span></th>
                            <td><input id="board_subject" name="board_subject" value="" class="tbox01"/></td>
                        </tr>
                        <tr>
                            <th>작성자<span class="t_red">*</span></th>
                            <td><input id="board_writer" name="board_writer" value="" class="tbox01"/></td>
                        </tr>
                        <tr>
                            <th>내용<span class="t_red">*</span></th>
                            <td><textarea id="board_content" name="board_content" cols="10" rows="5" class="textarea01"></textarea></td>
                        </tr>
                    </tbody>
                </table>
            </form>
            <div class="btn_right mt15">
                <button type="button" class="btn black mr5" onclick="javascript:goBoardList();">목록으로</button>
                <button type="button" class="btn black" onclick="javascript:insertBoardReply();">등록하기</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 
 

7 ) 게시판 답글 결과화면 

게시판 답글 작성화면
게시판 답글