우당탕탕 개발일지

48일차_페이징, MyBatis 맛보기 본문

비트캠프/이론 및 정리

48일차_페이징, MyBatis 맛보기

ujin302 2024. 9. 9. 18:05
반응형

저번 시간이어서! 

Git hub

https://github.com/ujin302/Web2024/tree/main/projectJSP

 

1. 프로젝트명 : projectJSP

기능 

  1. 게시물 목록 및 페이징
  2. 게시물 상세보기

jsp

  1. boardList.jsp
  2. boardItem.jsp

js

  1. BoardPaging.java

 

 

 

1-1. 게시물 목록 및 페이징

board 테이블

board 테이블 컬럼 설명

원글과 답글이 존재하고 답글을 달았을 경우 답글의 ref는 원글의 ref 이다. 

컬럼 seq subject ref step [ 원글 ]
원글 10 컴퓨터 10 0 원글 ret = seq
원글 11 과일 11 0 답글 ref = 원글 ref
답글 12 사과 11 1 [ 답글 ]
답급 13 키보드 10 원글 step = 0
답글 14  부사 11 2 답글 step = 원글 step + 1

 

 

 

 

boardList.jsp

<%@page import="dto.BoardDTO"%>
<%@page import="java.util.ArrayList"%>
<%@page import="DAO.BoardDAO"%>
<%@page import="board.bean.BoardPaging"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	BoardDAO boardDAO = BoardDAO.getInstance();
	int pg = Integer.parseInt(request.getParameter("pg"));
	int totalA = boardDAO.getTotalA();
	
	BoardPaging boardPaging = new BoardPaging();
	boardPaging.setCurrentPgae(pg);
	boardPaging.setPageBlock(3);
	boardPaging.setPageSize(2);
	boardPaging.setTotalA(totalA);
	System.out.println("current: " + boardPaging.getCurrentPgae());
	System.out.println("TotalA: " + boardPaging.getTotalA());
	
	boardPaging.makePagingHTML();
	ArrayList<BoardDTO> boardList = boardDAO.getBoardList(pg, boardPaging.getPageSize());
	
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<img alt="마루" src="../image/마루.jpg" onclick="location.href='../index.jsp'">
	<div id="board">    
	    <div class="exec">
	        <!-- 게시물 수  -->
	        총 게시물 수: <span><%=boardPaging.getTotalA() %></span>개
	    </div>
	    
	    <div class="example">
	        <table>
	            <thead>
	                <tr>
	                	<th class="no">번호</th>
	                    <th class="name">작성자</th>
	                    <th class="subject">제목</th>
	                    <td class="hit">조회수</td>
	                    <th class="logtime">작성일시</th>
	                </tr>
	            </thead>                
	            <tbody>
	                <%if(boardList.size() != 0) {%>
	                	<%for(BoardDTO boardDTO : boardList) {%>
		                	<tr>
		                		<td class="no"><%=boardDTO.getSeq()%></td>
		                		<td class="name"><%=boardDTO.getName()%></td>
		                		<td class="subject"><a href="./boardItem.jsp?no=<%=boardDTO.getSeq()%>"><%=boardDTO.getSubject()%></a></td>
		                		<td class="hit"><%=boardDTO.getHit()%></td>
		                		<td class="logtime"><%=boardDTO.getLogtime()%></td>
		                	</tr>
		                <%} %>
		            <%} %>
	            </tbody>
	        </table>
	        <div class="paging"><%=boardPaging.getPagingHTML() %></div>
	    </div>
	</div>
<script type="text/javascript">
function boardPaging(pg) {
	location.href = "boardList.jsp?pg=" + pg;
}
</script>
</body>
</html>

 

화면

 

 

 

boardItem.jsp

 

<%@page import="DAO.BoardDAO"%>
<%@page import="dto.BoardDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	int seq = Integer.parseInt(request.getParameter("no"));
	BoardDTO boardDTO = BoardDAO.getInstance().getBoardItme(seq);
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<img alt="마루" src="../image/마루.jpg" onclick="location.href='../index.jsp'">
	<form method="post" id="boardInfo">
		<table>
			<tr>
				<td colspan="2" align="center">
					<h2>게시물 작성</h2>
				</td>
			</tr>
			<tr>
				<th>제목</th>
				<td>
					<div><%=boardDTO.getSubject()%></div>
				</td>
			</tr>
			<tr>
				<th>작성자</th>
				<td>
					<div><%=boardDTO.getName()%></div>
				</td>
			</tr>
			<tr>
				<th>내용</th>
				<td>
					<div><%=boardDTO.getContent()%></div>
				</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<input class="btn" type="button" value="게시글 목록" onclick="location.href='./boardList.jsp?pg=1'">
				</td>
			</tr>
		</table>
	</form>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.7.1.min.js"></script>
</body>
</html>

 

화면

 

 

 

 

 

 

MyBatis

 

반응형

'비트캠프 > 이론 및 정리' 카테고리의 다른 글

50일차_EL/JSTL  (2) 2024.09.11
49일차_MyBatis  (0) 2024.09.10
47일차_회원정보 수정  (0) 2024.09.09
46일차_로그인, Cookie vs HttpSession  (0) 2024.09.05
45일차_회원가입  (0) 2024.09.05