jspblog : boardlist paging
This commit is contained in:
@@ -34,8 +34,8 @@ public class BoardDao {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public List<Board> findAll() {
|
||||
String sql = "select * from board order by id desc";
|
||||
public List<Board> findAll(int page) {
|
||||
String sql = "select * from board order by id desc limit ?, 4";
|
||||
Connection conn = DB.getConnection();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
@@ -44,6 +44,7 @@ public class BoardDao {
|
||||
if (conn != null) {
|
||||
try {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setInt(1, page * 4);
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Board board = Board.builder()
|
||||
|
||||
@@ -18,7 +18,7 @@ public class BoardService {
|
||||
return boardDao.write(dto);
|
||||
}
|
||||
|
||||
public List<Board> 글목록보기() {
|
||||
return boardDao.findAll();
|
||||
public List<Board> 글목록보기(int page) {
|
||||
return boardDao.findAll(page);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,8 @@ public class BoardController extends HttpServlet {
|
||||
break;
|
||||
}
|
||||
case "list" :
|
||||
List<Board> boards = boardService.글목록보기();
|
||||
int page = Integer.parseInt(request.getParameter("page"));
|
||||
List<Board> boards = boardService.글목록보기(page);
|
||||
request.setAttribute("boards", boards);
|
||||
request.getRequestDispatcher("board/list.jsp").forward(request, response);
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@
|
||||
</c:forEach>
|
||||
<br />
|
||||
<ul class="pagination justify-content-center">
|
||||
<li class="page-item disabled"><a class="page-link" href="#">Previous</a></li>
|
||||
<li class="page-item"><a class="page-link" href="#">Next</a></li>
|
||||
<li class="page-item"><a class="page-link" href="${pageContext.request.contextPath}/board?cmd=list&page=${param.page-1}">Previous</a></li>
|
||||
<li class="page-item"><a class="page-link" href="${pageContext.request.contextPath}/board?cmd=list&page=${param.page+1}">Next</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
|
||||
|
||||
<%
|
||||
request.getRequestDispatcher("board?cmd=list").forward(request, response);
|
||||
request.getRequestDispatcher("board?cmd=list&page=0").forward(request, response);
|
||||
%>
|
||||
Reference in New Issue
Block a user