Skip to content

Commit 6d5092f

Browse files
committed
Feat: Reply Pagination View Javascript
modify: ReplyMapper.xml - pagination DESC
1 parent c125138 commit 6d5092f

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/main/resources/mapper/ReplyMapper.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
SELECT replyNo, articleNo, replyText, replyWriter, regDate, updateDate
3434
FROM tb_reply
3535
WHERE articleNo = #{articleNo}
36-
ORDER BY replyNo
36+
ORDER BY replyNo DESC
3737
LIMIT #{criteria.pageStart}, #{criteria.perPageNum}
3838
</select>
3939

src/main/webapp/WEB-INF/views/tutorial/reply_test.jsp

+55-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@
121121

122122
<script>
123123
var articleNo = 1;
124-
getReplies();
124+
var replyPageNum = 1;
125+
// getReplies();
126+
getRepliesPaging(replyPageNum);
125127
126128
// 댓글 목록 출력
127129
function getReplies() {
@@ -241,6 +243,58 @@
241243
}
242244
});
243245
});
246+
247+
// 댓글 목록 페이징 함수
248+
function getRepliesPaging(page) {
249+
$.getJSON("/replies/" + articleNo + "/" + page, function (data) {
250+
console.log(data);
251+
252+
var str = "";
253+
254+
$(data.replies).each(function () {
255+
str += "<li data-replyNo='" + this.replyNo + "' class=replyLi'>"
256+
+ "<p class='replyText'>" + this.replyText + "</p>"
257+
+ "<p class='replyWriter'>" + this.replyWriter + "</p>"
258+
+ "<button type='button' class='btn btn-xs btn-success' data-toggle='modal' data-target='#modifyModal'>댓글 수정</button>"
259+
+ "</li>"
260+
+ "<hr/>";
261+
});
262+
$("#replies").html(str);
263+
264+
// 페이지 번호 출력 함수 호출
265+
printPageNumbers(data.pageMaker);
266+
});
267+
}
268+
269+
// 댓글 목록 페이지 번호 출력 함수
270+
function printPageNumbers(pageMaker) {
271+
var str = "";
272+
273+
// 이전 버튼 활성화
274+
if (pageMaker.prev) {
275+
str += "<li><a href='" + (pageMaker.startPage - 1) + "'>이전</a></li>";
276+
}
277+
278+
// 페이지 번호
279+
for (var i = pageMaker.startPage, len = pageMaker.endPage; i <= len; ++i) {
280+
var strClass = pageMaker.criteria.page == i ? 'class=active' : '';
281+
str += "<li " + strClass+ "><a href='" + i + "'>" + i + "</a></li>";
282+
}
283+
284+
// 다음 버튼 활성화
285+
if (pageMaker.next) {
286+
str += "<li><a href='" + (pageMaker.endPage + 1) + "'>다음</a></li>";
287+
}
288+
289+
$(".pagination-sm").html(str);
290+
}
291+
292+
// 목록 페이지 번호 클릭 이벤트
293+
$(".pagination").on("click", "li a", function (event) {
294+
event.preventDefault();
295+
replyPageNum = $(this).attr("href"); // 목록 페이지 번호 추출
296+
getRepliesPaging(replyPageNum); // 목록 페이지 호출
297+
})
244298
</script>
245299

246300
</body>

0 commit comments

Comments
 (0)