728x90
댓글 페이징 처리를 숨겨야한다.
<%@ 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="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>그냥 게시판</title>
</head>
<style>
.container{
align-content : center;
width: 1200px;
height: 600px;
}
.content{
width: 1000px;
height: 550px;
}
</style>
<body>
<div class="container"> <%-- container 영역 div --%>
<jsp:include page="../inc/top.jsp" />
<jsp:include page="../inc/sidebar.jsp" />
<div class="content"> <%-- content영역 div --%>
<h1>글 읽기</h1>
<table >
<tr><td>글번호</td><td>${boardDTO.no}</td></tr>
<tr><td>글쓴이</td><td>${boardDTO.id}</td></tr>
<tr><td>조회수</td><td>${boardDTO.readcount}</td></tr>
<tr><td>작성일</td><td><fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${boardDTO.writetime}"/></td></tr>
<tr><td>글제목</td><td>${boardDTO.subject}</td></tr>
<tr><td>글내용</td><td>${boardDTO.content}</td></tr>
</table>
<div style="display: center">
<c:if test="${!empty sessionScope.id }">
<c:if test="${sessionScope.id eq boardDTO.id}">
<a href="${pageContext.request.contextPath}/board/update?no=${boardDTO.no}"><input type="button" value="글 수정"></a> <a href="${pageContext.request.contextPath}/board/delete?no=${boardDTO.no}"><input type="button" value="글 삭제"></a>
</c:if>
</c:if>
<a href="${pageContext.request.contextPath}/board/list"><input type="button" value="글 목록"></a>
</div>
<hr>
<c:if test="${empty sessionScope.id }">
<p><b>댓글은 회원만 작성 및 확인 할 수 있습니다. 확인을 위해서 회원 가입해주세요.</b></p><br>
</c:if>
<c:if test="${!empty sessionScope.id }">
댓글<br>
<form action="${pageContext.request.contextPath}/board/replyInsertPro" method="post">
<input type="hidden" name="no" value="${boardDTO.no }">
<input type="hidden" name="id" value="${sessionScope.id }">
<input type="text" value="${sessionScope.id }" readonly="readonly"><br>
<textarea rows="5" cols="30" style="width: 792px; height: 35px" placeholder="내용을 작성해주세요." name="replyContent"></textarea><br>
<span style="float: right;"><input type="checkbox" name="replyHidden" value="true">비밀글 <input type="hidden" name="replyHidden" value="false"><input type="submit" value="작성"></span>
</form>
댓글 목록 <sub>비밀 댓글은 굵게 표시됩니다.</sub><br>
<c:if test="${empty replyList}">
작성된 댓글이 없습니다.
</c:if>
<c:if test="${!empty replyList}">
<table>
<c:forEach var="replyDTO" items="${replyList}">
<tr>
<c:choose>
<c:when test="${replyDTO.replyHidden && replyDTO.id != sessionScope.id}">
<td style="width: 600px">작성자: ${replyDTO.id}</td>
<td style="width: 1000px">비밀글입니다.</td>
<td style="width: 600px">작성시간: <fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${replyDTO.replyWriteTime}" /></td>
</c:when>
<c:otherwise>
<td style="width: 600px">작성자: ${replyDTO.id}</td>
<td style="width: 1000px"><b>내용: ${replyDTO.replyContent}</b></td>
<td style="width: 600px">작성시간: <fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${replyDTO.replyWriteTime}" /></td>
</c:otherwise>
</c:choose>
</tr>
</c:forEach>
</table>
</c:if>
<div style="float: right;">
<c:if test="${pageDTO.startPage > pageDTO.pageBlock}">
<a href="${pageContext.request.contextPath}/board/content?no=${boardDTO.no}&pageNum=${replyPageDTO.startPage - replyPageDTO.pageBlock}">Prev</a>
</c:if>
<c:forEach var="i" begin="${replyPageDTO.startPage}" end="${replyPageDTO.endPage}" step="1">
<a href="${pageContext.request.contextPath}/board/content?no=${boardDTO.no}&pageNum=${i}">${i} </a>
</c:forEach>
<c:if test="${replyPageDTO.endPage < replyPageDTO.pageCount}">
<a href="${pageContext.request.contextPath}/board/content?no=${boardDTO.no}&pageNum=${replyPageDTO.startPage + replyPageDTO.pageBlock}">Next</a>
</c:if>
</div>
</c:if>
</div> <%-- content영역 div --%>
<jsp:include page="../inc/footer.jsp" />
</div> <%-- container 영역 div --%>
</body>
</html>
댓글 페이징 처리를 로그인 했을 때만 확인할 수 있게 변경했다.
문제 사항
- 변수명을 잘 못 한 것 같다.
id라는 것이 board, reply, member에 있는데 막상 만들다 보니 점점 어디의 어떤 게 id인지 혼동이 온다. - 유사한 점이 많아 게시판과 댓글을 한 로직에 코드를 작성했다.
막상 점점 분량이 커지다보니 꼬인다.
해결 방법
- 변수명을 을 한 눈에 알아 볼 수 있도록 작성한다.
id 같은 경우 member_id, board_id, reply_id로 하도록 한다. - 유사한 점이 많더라도 로직을 분리한다.
이전 글에서 마주한 문제를 해결하려고 노력하다보니 코드가 어디서부터 어떻게 꼬인지 잘 모르겠다.
몇 주동안 일이 생겨서 흐름이 끊긴 것도 큰 것 같다.
일단 임시 방편으로
<%@ 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="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>그냥 게시판</title>
</head>
<style>
.container{
align-content : center;
width: 1200px;
height: 600px;
}
.content{
width: 1000px;
height: 550px;
}
</style>
<body>
<div class="container"> <%-- container 영역 div --%>
<jsp:include page="../inc/top.jsp" />
<jsp:include page="../inc/sidebar.jsp" />
<div class="content"> <%-- content영역 div --%>
<h1>글 읽기</h1>
<table >
<tr><td>글번호</td><td>${boardDTO.no}</td></tr>
<tr><td>글쓴이</td><td>${boardDTO.id}</td></tr>
<tr><td>조회수</td><td>${boardDTO.readcount}</td></tr>
<tr><td>작성일</td><td><fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${boardDTO.writetime}"/></td></tr>
<tr><td>글제목</td><td>${boardDTO.subject}</td></tr>
<tr><td>글내용</td><td>${boardDTO.content}</td></tr>
</table>
<div style="display: center">
<c:if test="${!empty sessionScope.id }">
<c:if test="${sessionScope.id eq boardDTO.id}">
<a href="${pageContext.request.contextPath}/board/update?no=${boardDTO.no}"><input type="button" value="글 수정"></a> <a href="${pageContext.request.contextPath}/board/delete?no=${boardDTO.no}"><input type="button" value="글 삭제"></a>
</c:if>
</c:if>
<a href="${pageContext.request.contextPath}/board/list"><input type="button" value="글 목록"></a>
</div>
<hr>
<c:if test="${empty sessionScope.id }">
<p><b>댓글은 회원만 작성 및 확인 할 수 있습니다. 확인을 위해서 회원 가입해주세요.</b></p><br>
</c:if>
<c:if test="${!empty sessionScope.id }">
댓글<br>
<form action="${pageContext.request.contextPath}/board/replyInsertPro" method="post">
<input type="hidden" name="no" value="${boardDTO.no }">
<input type="hidden" name="id" value="${sessionScope.id }">
<input type="text" value="${sessionScope.id }" readonly="readonly"><br>
<textarea rows="5" cols="30" style="width: 792px; height: 35px" placeholder="내용을 작성해주세요." name="replyContent"></textarea><br>
<span style="float: right;"><input type="submit" value="작성"></span>
</form>
댓글 목록 <sub></sub><br>
<c:if test="${empty replyList}">
작성된 댓글이 없습니다.
</c:if>
<c:if test="${!empty replyList}">
<table>
<c:forEach var="replyDTO" items="${replyList}">
<tr>
<td style="width: 1600px">내용: ${replyDTO.replyContent}</td>
<td style="width: 600px">작성시간: <fmt:formatDate pattern="yyyy-MM-dd hh:mm:ss" value="${replyDTO.replyWriteTime}" /></td>
</tr>
</c:forEach>
</table>
</c:if>
<div style="float: right;">
<c:if test="${pageDTO.startPage > pageDTO.pageBlock}">
<a href="${pageContext.request.contextPath}/board/content?no=${boardDTO.no}&pageNum=${replyPageDTO.startPage - replyPageDTO.pageBlock}">Prev</a>
</c:if>
<c:forEach var="i" begin="${replyPageDTO.startPage}" end="${replyPageDTO.endPage}" step="1">
<a href="${pageContext.request.contextPath}/board/content?no=${boardDTO.no}&pageNum=${i}">${i} </a>
</c:forEach>
<c:if test="${replyPageDTO.endPage < replyPageDTO.pageCount}">
<a href="${pageContext.request.contextPath}/board/content?no=${boardDTO.no}&pageNum=${replyPageDTO.startPage + replyPageDTO.pageBlock}">Next</a>
</c:if>
</div>
</c:if>
</div> <%-- content영역 div --%>
<jsp:include page="../inc/footer.jsp" />
</div> <%-- container 영역 div --%>
</body>
</html>
원래 생각과는 다르지만 댓글 구현까지는 완료했다. 수정, 보완할 여지가 많다. 수시로 보완할 예정이다.
728x90
'organize > 프로젝트' 카테고리의 다른 글
1차 프로젝트 추가 - 암호화1 (0) | 2024.12.22 |
---|---|
컬렉션 프레임워크(1) Map (0) | 2024.12.03 |
justBoard15 댓글 구현(5) 댓글 페이지 처리 (0) | 2024.10.20 |
justBoard14 댓글 구현(4) (0) | 2024.10.15 |
justBoard13 댓글 구현(3) 데이터 (0) | 2024.10.13 |