<대분류1>
🤦🏻♀️ 게시판 상세 조회
더보기
1. .jsp 등 프로젝트 클래스
ㅇ
🤦🏻♀️ 게시판 수정
(selece 내의 option 창에서 '카테고리 선택'을 눌렀을 때는 넘어가지 않도록 변경, 등록 폼에도 수정)
더보기
1. .boardUpdateForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList, com.insertcoin.board.model.vo.Board, com.insertcoin.common.model.vo.Attachment, com.insertcoin.game.model.vo.Game" %>
<%
// 필요한 데이터 먼저 뽑기
ArrayList<Game> list = (ArrayList<Game>)request.getAttribute("list");
Board b = (Board)request.getAttribute("b");
Attachment at = (Attachment)request.getAttribute("at");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>자유게시판 게시글 수정</title>
<!-- CSS 스타일시트 -->
<link href="resources/css/boardUpdateForm.css" rel="stylesheet">
</head>
<body>
<!-- 전체 영역 -->
<div class="wrap">
<%@ include file = "../../views/common/header.jsp" %>
<!-- 컨텐츠 영역 -->
<div class="content_container">
<div class="outer">
<div id="title">자유게시판</div>
<form id="update-form" action="<%= contextPath %>/update.bo" method="post" enctype="multipart/form-data" name="updateForm">
<input type="hidden" name="genNo" value="<%= b.getGenNo() %>">
<table align="center" class="table-area">
<tr>
<td colspan="2">
<!--<input type="text" name="gameName" class="input_text" placeholder=" 게임 태그를 입력해 주세요"> -->
</td>
</tr>
<tr>
<td>
<select name="genCategory" id="select_category" required>
<option value="" selected disabled>카테고리 선택</option>
<option value="잡담">잡담</option>
<option value="질문">질문</option>
<option value="공략">공략</option>
</select>
<script>
$(function() {
$("#update-form option").each(function() {
if($(this).text().equals(<%= b.getGenCategory() %>)) {
$(this).attr("selected", true);
}
});
});
</script>
</td>
<td>
<input id="input_title" type="text" name="genTitle" value="<%= b.getGenTitle() %>" required>
</td>
</tr>
<tr>
<td colspan="2">
<textarea class="input_text" name="genContent" required><%= b.getGenContent() %></textarea>
</td>
</tr>
<tr>
<th colspan="2">
<div id="attachment_content"> 첨부파일
<% if(at != null) { %>
<%= at.getAttachmentName() %>
<!-- 기존의 파일번호와 수정명을 hidden으로 추가적으로 넘기기 => 찾아서 삭제해야 하니까 -->
<input type="hidden" name="originFileNo" value="<%= at.getAttachmentNo() %>">
<input type="hidden" name="originFileName" value="<%= at.getAttachmentRename() %>">
<% } %>
<input type="file" name="reUpfile"></div>
</th>
</tr>
</table>
<br><br>
<div align="center">
<button id="reset_button">취소</button>
<button id="submit_button" onclick="categoryCheck();">수정</button>
</div>
</form>
</div>
</div>
<%@ include file = "../../views/common/footer.jsp" %>
</div>
<script>
function categoryCheck() {
var updateForm = document.updateForm;
if(updateForm.genCategory.value=="") {
alert("카테고리를 선택하셔야 게시글을 등록할 수 있습니다.");
updateForm.genCategory.focus();
return false;
}
}
</script>
</body>
</html>
2. boardDetailView.jsp 수정하기 버튼에 링크 달기
<% if(loginUser != null && loginUser.getMemNickname().equals(b.getMemNo())) { %>
<button class="table_button" onclick="location.href='<%= contextPath %>/updateForm.bo?genNo=<%= b.getGenNo() %>'">수정</button>
<button class="table_button">삭제</button>
<button type="button" id="red_board" class="btn btn-primary" data-toggle="modal" data-target="#myReport">신고</button>
<% } %>
<button class="table_button" onclick="goToList();">목록</button>
3. BoardUpdateFormController(URL mapping: /updateForm.bo
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 게임 정보들 전체 조회, 해당 게시글 정보 조회, 게시글에 딸린 첨부파일 정보 조회
BoardService bService = new BoardService();
int genNo = Integer.parseInt(request.getParameter("genNo"));
ArrayList<Game> list = bService.selectGameList();
Board b = bService.selectBoard(genNo);
Attachment at = bService.selectAttachment(genNo);
request.setAttribute("list", list);
request.setAttribute("b", b);
request.setAttribute("at", at);
request.getRequestDispatcher("views/board/boardUpdateForm.jsp").forward(request, response);
}
4. BoardUpdateController(URL mapping: /update.bo)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
if(ServletFileUpload.isMultipartContent(request)) { // 만약 multipart/form-data 형식으로 요청 들어왔다면
int maxSize = 10 * 1024 * 1024;
String savePath = request.getSession().getServletContext().getRealPath("/resources/image/board/gen/post/");
MultipartRequest multiRequest = new MultipartRequest(request, savePath, maxSize, "UTF-8", new MyFileRenamePolicy());
int genNo = Integer.parseInt(multiRequest.getParameter("genNo"));
String genCategory = multiRequest.getParameter("genCategory");
String gameNo = multiRequest.getParameter("gameNo");
String genTitle = multiRequest.getParameter("genTitle");
String genContent = multiRequest.getParameter("genContent");
Board b = new Board();
b.setGenNo(genNo);
b.setGenCategory(genCategory);
b.setGameNo(gameNo);
b.setGenTitle(genTitle);
b.setGenContent(genContent);
Attachment at = null;
if(multiRequest.getOriginalFileName("reUpfile") != null) { // 새로 첨부한 파일이 있다면
at = new Attachment();
at.setAttachmentName(multiRequest.getOriginalFileName("reUpfile"));
at.setAttachmentRename(multiRequest.getFilesystemName("reUpfile"));
at.setAttachmentPath("resources/image/board/gen/post/");
// 기존 파일이 있을 경우
if(multiRequest.getParameter("originFileNo") != null) {
at.setAttachmentNo(Integer.parseInt(multiRequest.getParameter("originFileNo")));
} else {
at.setGenNo(genNo);
}
}
System.out.println(at);
int result = new BoardService().updateBoard(b, at);
if(result > 0) {
// 만약 기존 첨부파일이 있고 새로운 첨부파일도 있을 경우 서버에 있던 기존 첨부파일을 삭제
if(multiRequest.getParameter("originFileName") != null && multiRequest.getOriginalFileName("reUpfile") != null) {
new File(savePath + multiRequest.getParameter("originFileName")).delete();
}
request.getSession().setAttribute("alertMsg", "게시글이 성공적으로 수정되었습니다.");
response.sendRedirect(request.getContextPath() + "/detail.bo?genNo=" + genNo); // URL 요청
} else { // 수정 실패
request.setAttribute("errorMsg", "게시글 수정 실패");
request.getRequestDispatcher("views/common/errorPage.jsp").forward(request, response);
}
}
}
5. BoardService
// 게시글 수정 서비스
public int updateBoard(Board b, Attachment at) {
Connection conn = getConnection();
// 3가지 경우 모두 공통적으로 실행해야 하는 GEN_BOARD UPDATE 구문
int result1 = new BoardDao().updateBoard(conn, b);
// 0으로 설정 시 기존 첨부파일 없다면 무조건 false이기 때문에 기본값을 1로 세팅
int result2 = 1;
if(at != null) { // 새롭게 첨부된 파일이 있는 경우
if(at.getAttachmentNo() != 0) { // 기존 첨부파일도 있다면
// Attachment 테이블에 update
result2 = new BoardDao().updateAttachment(conn, at);
} else { // 기존 첨부파일은 없다면
// Attachment 테이블에 insert
result2 = new BoardDao().insertNewAttachment(conn, at);
}
}
// 모든 요청이 다 성공했을 경우에만 commit
if(result1 > 0 && result2 > 0) {
commit(conn);
} else {
rollback(conn);
}
close(conn);
return result1 * result2;
}
6. BoardDao
public int updateBoard(Connection conn, Board b) {
// UPDATE 문 => int(처리된 행의 개수)
int result = 0;
PreparedStatement pstmt = null;
String sql = prop.getProperty("updateBoard");
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, b.getGenCategory());
pstmt.setString(2, b.getGenTitle());
pstmt.setString(3, b.getGenContent());
pstmt.setString(4, b.getGameNo());
pstmt.setInt(5, b.getGenNo());
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt);
}
return result;
}
public int updateAttachment(Connection conn, Attachment at) {
// UPDATE => int
int result = 0;
PreparedStatement pstmt = null;
String sql = prop.getProperty("updateAttachment");
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, at.getAttachmentName());
pstmt.setString(2, at.getAttachmentRename());
pstmt.setInt(3, at.getAttachmentNo());
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt);
}
return result;
}
public int insertNewAttachment(Connection conn, Attachment at) {
// INSERT => int
int result = 0;
PreparedStatement pstmt = null;
String sql = prop.getProperty("insertNewAttachment");
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, at.getGenNo());
pstmt.setString(2, at.getAttachmentName());
pstmt.setString(3, at.getAttachmentRename());
pstmt.setString(4, at.getAttachmentPath());
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt);
}
return result;
}
7. board-mapper.xml
<entry key="updateBoard">
UPDATE GEN_BOARD
SET GEN_CATEGORY = ?
, GEN_TITLE = ?
, GEN_CONTENT = ?
, GAME_NO = ?
WHERE GEN_NO = ?
AND GEN_SHOW = 'Y'
</entry>
<entry key="updateAttachment">
UPDATE ATTACHMENT
SET ATTACHMENT_NAME = ?
, ATTACHMENT_RENAME = ?
, ATTACHMENT_UPLOAD_DATE = SYSDATE
WHERE ATTACHMENT_NO = ?
</entry>
<entry key="insertNewAttachment">
INSERT INTO ATTACHMENT(ATTACHMENT_NO
, GEN_NO
, ATTACHMENT_NAME
, ATTACHMENT_RENAME
, ATTACHMENT_PATH)
VALUES (SEQ_ATTACHMENT_NO.NEXTVAL
, ?
, ?
, ?
, ?)
</entry>
🤦🏻♀️ 게시판 삭제
더보기
1. boardDetailView.jsp 삭제 버튼 링크 걸기
<% if(loginUser != null && loginUser.getMemNickname().equals(b.getMemNo())) { %>
<button class="table_button" onclick="location.href='<%= contextPath %>/updateForm.bo?genNo=<%= b.getGenNo() %>'">수정</button>
<button class="table_button" onclick="location.href='<%= contextPath %>/delete.bo?genNo=<%= b.getGenNo() %>'">삭제</button>
<button type="button" id="red_board" class="btn btn-primary" data-toggle="modal" data-target="#myReport">신고</button>
<% } %>
<button class="table_button" onclick="goToList();">목록</button>
2. BoardDeleteController (URL mapping: /delete.bo)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
int genNo = Integer.parseInt(request.getParameter("genNo"));
int result = new BoardService().deleteBoard(genNo);
if(result > 0) {
request.getSession().setAttribute("alertMsg", "게시글이 성공적으로 삭제되었습니다.");
response.sendRedirect(request.getContextPath() + "/list.bo?currentPage=1");
} else {
request.setAttribute("errorMsg", "게시글 삭제 실패");
request.getRequestDispatcher("views/common/errorPage.jsp").forward(request, response);
}
}
3. BoardService
// 게시글 삭제용 서비스
public int deleteBoard(int genNo) {
Connection conn = getConnection();
int result = new BoardDao().deleteBoard(conn, genNo);
if(result > 0) {
commit(conn);
} else {
rollback(conn);
}
return result;
}
4. BoardDao
public int deleteBoard(Connection conn, int genNo) {
// UPDATE => int
int result = 0;
PreparedStatement pstmt = null;
String sql = prop.getProperty("deleteBoard");
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, genNo);
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt);
}
return result;
}
5. board-mapper.xml
<entry key="deleteBoard">
UPDATE GEN_BOARD
SET GEN_SHOW = 'N'
WHERE GEN_NO = ?
</entry>
🤦🏻♀️ 완료된 소분류
확인할 부분
더보기
ㅇ
<댓글>
🤦🏻♀️ 댓글 조회
더보기
1. 폼 하드 코딩
2. GenCommentListController 서블릿 (URL mapping: /gclist.bo)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 게시글 번호 뽑기
int genNo = Integer.parseInt(request.getParameter("genNo"));
// 게시글 번호를 서비스를 전달하면서 요청 처리 후 결과 받기
ArrayList<GenComment> list = new BoardService().selectReplyList(genNo);
// GSON을 이용해서 응답 => ArrayList를 자바 스크립트 배열 형태로 변환
response.setContentType("application/json; charset=UTF-8");
new Gson().toJson(list, response.getWriter()); // 응답할 데이터, 통로 객체를 차례로 넘김
}
3. GenComment
package com.insertcoin.board.model.vo;
public class GenComment {
// 필드부
private int genCommentNo;
private String genCommentContent;
private int genNo;
private String memNo;
private String genCommentRegister;
private String genCommentShow;
// 생성자부
public GenComment() {
super();
}
public GenComment(int genCommentNo, String genCommentContent, int genNo, String memNo, String genCommentRegister,
String genCommentShow) {
super();
this.genCommentNo = genCommentNo;
this.genCommentContent = genCommentContent;
this.genNo = genNo;
this.memNo = memNo;
this.genCommentRegister = genCommentRegister;
this.genCommentShow = genCommentShow;
}
// 댓글 리스트 조회용 생성자
public GenComment(int genCommentNo, String genCommentContent, String memNo, String genCommentRegister) {
super();
this.genCommentNo = genCommentNo;
this.genCommentContent = genCommentContent;
this.memNo = memNo;
this.genCommentRegister = genCommentRegister;
}
// 메소드부
public int getGenCommentNo() {
return genCommentNo;
}
public void setGenCommentNo(int genCommentNo) {
this.genCommentNo = genCommentNo;
}
public int getGenNo() {
return genNo;
}
public void setGenNo(int genNo) {
this.genNo = genNo;
}
public String getMemNo() {
return memNo;
}
public void setMemNo(String memNo) {
this.memNo = memNo;
}
public String getGenCommentContent() {
return genCommentContent;
}
public void setGenCommentContent(String genCommentContent) {
this.genCommentContent = genCommentContent;
}
public String getGenCommentRegister() {
return genCommentRegister;
}
public void setGenCommentRegister(String genCommentRegister) {
this.genCommentRegister = genCommentRegister;
}
public String getGenCommentShow() {
return genCommentShow;
}
public void setGenCommentShow(String genCommentShow) {
this.genCommentShow = genCommentShow;
}
@Override
public String toString() {
return "BoardComment [genCommentNo=" + genCommentNo + ", genNo=" + genNo + ", memNo=" + memNo
+ ", genCommentContent=" + genCommentContent + ", genCommentRegister=" + genCommentRegister
+ ", genCommentShow=" + genCommentShow + "]";
}
}
4. BoardService
public ArrayList<GenComment> selectGenCommentList(int genNo) {
Connection conn = getConnection();
ArrayList<GenComment> list = new BoardDao().selectGenCommentList(conn, genNo);
close(conn);
return list;
}
5. BoardDao
public ArrayList<GenComment> selectGenCommentList(Connection conn, int genNo) {
// SELECT문 => ResultSet 객체 (여러 행 조회)
ArrayList<GenComment> list = new ArrayList<>();
PreparedStatement pstmt = null;
ResultSet rset = null;
String sql = prop.getProperty("selectGenCommentList");
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, genNo);
rset = pstmt.executeQuery();
while(rset.next()) {
list.add(new GenComment(rset.getInt("GEN_COMMENT_NO"),
rset.getString("GEN_COMMENT_CONTENT"),
rset.getString("MEM_EMAIL"),
rset.getString("GEN_COMMENT_REGISTER_DATE")));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rset);
close(pstmt);
}
return list;
}
6. board-mapper.xml
<entry key="slectGenCommentList">
SELECT GEN_COMMENT_NO
, GEN_COMMENT_CONTENT
, M.MEM_EMAIL
, TO_CHAR(GEN_COMMENT_REGISTER_DATE, 'YY/MM/DD HH:MI:SS') GEN_COMMENT_REGISTER_DATE
FROM GEN_COMMENT C
JOIN MEMBER M ON (C.MEM_NO = M.MEM_NO)
WHERE GEN_NO = ?
AND GEN_COMMENT_SHOW = 'Y'
ORDER BY GEN_COMMENT_NO DESC
</entry>
7. boardDetailView.jsp 동적코딩(수정 부분만 발췌)
<td colspan="2">
<div id="comment_count"></div>
</td>
</tr>
</tbody>
</table>
<table class="comment_table">
<!--
<tr>
<td rowspan="2" width="5%">
<img src="resources/image/profile/profile_default.png" id="profile_photo">
</td>
<td>
<div class="comment_info1">
<div>내닉넴짱짱</div>
</div>
</td>
<td>
<div class="comment_info2">
<div>2022.10.23 12:02</div>
</div>
</td>
<td>
<button id="comment_info3" class="btn btn-primary" data-toggle="modal" data-target="#myReport">신고</button>
</td>
</tr>
<tr class="line">
<td>어디보자... 점점 구색을 갖추는듯하나 아직 고칠 게 많아 보입니다 ^^</td>
</tr>
-->
<thead>
</thead>
<tbody>
<% if(loginUser != null) { %>
<!-- 로그인이 되어 있을 경우 -->
<tr>
<td colspan="4">
<div class=comment_container> 댓글쓰기 <br>
<textarea class="comment_textarea" placeholder="명예훼손, 개인정보 유출, 분쟁 유발, 허위사실 유포 등의 글은 이용약관에 의해 제재는 물론 법률에 의해 처벌받을 수 있습니다. 건전한 커뮤니티를 위해 자제를 당부드립니다."></textarea>
<button id="comment_submit" onclick="insertGenComment();">등록</button>
</div>
</td>
</tr>
<% } else { %>
<!-- 로그인이 되어 있지 않다면 -->
<tr>
<td colspan="4">
<div class=comment_container> 댓글쓰기 <br>
<textarea class="comment_textarea" readonly">로그인 후 이용해 주세요.</textarea>
<button id="comment_submit" disabled>등록</button>
</div>
</td>
</tr>
<% } %>
</tbody>
</table>
<script>
$(function() {
selectGenCommentList();
});
function selectGenCommentList() {
$.ajax({
url : "gclist.bo",
data : {genNo : <%= b.getGenNo() %>},
success : function(list) {
// console.log(list);
var result1 = "";
for (var i in list) { // i: 0, 1, 2, 3, ..., 마지막 인덱스값
result1 += "<tr>"
// + "<td rowspan='2' width='5%'><img src="resources/image/profile/profile_default.png" id="profile_photo"></td>"
+ "<td colspan='2'><div class='comment_info1'>" + list[i].memNo + "</div></td>"
+ "<td><div class='comment_info2'>" + list[i].genCommentRegister + "</div></td>"
+ "<td><button class='comment_info3 btn btn-danger' data-toggle='modal' data-target='#myReport'>신고</button></td></tr>"
+ "<tr class='line'><td>" + list[i].genCommentContent + "</td></tr>"
}
$(".comment_table thead").html(result1);
var result2 = list.length;
$("#comment_count").text("댓글 " + result2 + "개");
},
error : function() {
console.log("댓글 리스트 조회용 ajax 통신 실패");
}
});
}
</script>
🤦🏻♀️ 댓글 작성
더보기
1. boardDetailView.jsp
<tbody>
<% if(loginUser != null) { %>
<!-- 로그인이 되어 있을 경우 -->
<tr>
<td colspan="4">
<div class=comment_container> 댓글쓰기 <br>
<textarea class="comment_textarea" placeholder="명예훼손, 개인정보 유출, 분쟁 유발, 허위사실 유포 등의 글은 이용약관에 의해 제재는 물론 법률에 의해 처벌받을 수 있습니다. 건전한 커뮤니티를 위해 자제를 당부드립니다."></textarea>
<button id="comment_submit" onclick="insertGenComment();">등록</button>
</div>
</td>
</tr>
<% } else { %>
<!-- 로그인이 되어 있지 않다면 -->
<tr>
<td colspan="4">
<div class=comment_container> 댓글쓰기 <br>
<textarea class="comment_textarea" readonly">로그인 후 이용해 주세요.</textarea>
<button id="comment_submit" disabled>등록</button>
</div>
</td>
</tr>
<% } %>
</tbody>
</table>
<script>
$(function() {
selectGenCommentList();
// 1초 간격마다 selectGenCommentList 함수 실행
setInterval(selectGenCommentList, 1000);
});
function insertGenComment() {
$.ajax({
url : "gcinsert.bo",
data : {content : $("#genCommentContent").val(),
genNo : <%= b.getGenNo() %>
},
type : "post",
success : function(result) {
// result에 댓글 작성 성공 시 1, 실패 시 0
if(result > 0) {
// 갱신된 댓글 리스트 조회
selectGenCommentList();
// textarea 새로고침하지 않아도 초기화 효과
$("#genCommentContent").val("");
} else {
alert("댓글 작성에 실패했습니다.")
}
},
erroe : function() {
console.log("댓글 작성용 ajax 통신 실패!");
}
});
}
function selectGenCommentList() {
$.ajax({
url : "gclist.bo",
data : {genNo : <%= b.getGenNo() %>},
success : function(list) {
// console.log(list);
var result1 = "";
for (var i in list) { // i: 0, 1, 2, 3, ..., 마지막 인덱스값
result1 += "<tr>"
// + "<td rowspan='2' width='5%'><img src="resources/image/profile/profile_default.png" id="profile_photo"></td>"
+ "<td colspan='2'><div class='comment_info1'>" + list[i].memNo + "</div></td>"
+ "<td><div class='comment_info2'>" + list[i].genCommentRegister + "</div></td>"
+ "<td><button class='comment_info3 btn btn-danger' data-toggle='modal' data-target='#myReport'>신고</button></td></tr>"
+ "<tr class='line'><td>" + list[i].genCommentContent + "</td></tr>"
}
$(".comment_table thead").html(result1);
var result2 = list.length;
$("#comment_count").text("댓글 " + result2 + "개");
},
error : function() {
console.log("댓글 리스트 조회용 ajax 통신 실패");
}
});
}
</script>
2.GenCommentInsertController (URL mapping: /gcinsert.bo)
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// 요청 시 전달값 뽑기
// content: 댓글 내용
String genCommentContent = request.getParameter("content");
// genNo: 참조 게시글 번호
int genNo = Integer.parseInt(request.getParameter("genNo"));
// 추가적으로 필요한 데이터: 댓글 작성자(지금 로그인한 회원)의 회원 번호
int memNo = ((Member)request.getSession().getAttribute("loginUser")).getMemNo();
// GenComment 타입으로 가공
GenComment gc = new GenComment();
gc.setGenCommentContent(genCommentContent);
gc.setGenNo(genNo);
gc.setMemNo(String.valueOf(memNo));
int result = new BoardService().insertGenComment(gc); // 댓글 작성 성공 시 1, 실패 시 0
// 응답 데이터 보내기
response.setContentType("text/html; charset=UTF-8");
response.getWriter().print(result);
}
3. BoardService
public int insertGenComment(GenComment gc) {
Connection conn = getConnection();
int result = new BoardDao().insertGenComment(conn, gc);
if(result > 0) {
commit(conn);
} else {
rollback(conn);
}
close(conn);
return result;
}
4. BoardDao
public int insertGenComment(Connection conn, GenComment gc) {
// INSERT문 => int (처리된 행의 개수)
int result = 0;
PreparedStatement pstmt = null;
String sql = prop.getProperty("insertGenComment");
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1,gc.getGenCommentContent());
pstmt.setInt(2, gc.getGenNo());
pstmt.setInt(3, Integer.parseInt(gc.getMemNo()));
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt);
}
return result;
}
5. board-mapper.xml
<entry key="insertGenComment">
INSERT INTO GEN_COMMENT (GEN_COMMENT_NO
, GEN_COMMENT_CONTENT
, GEN_NO
, MEM_NO)
VALUES (SEQ_GEN_COMMENT_NO.NEXTVAL
, ?
, ?
, ?)
</entry>