jspblog : board list firstpage, lastpage, page percent bar
This commit is contained in:
@@ -66,4 +66,25 @@ public class BoardDao {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int count() {
|
||||
String sql = "select count(*) from board";
|
||||
|
||||
Connection conn = DB.getConnection();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
|
||||
if (conn != null) {
|
||||
try {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
rs = pstmt.executeQuery();
|
||||
if (rs.next()) return rs.getInt(1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
DB.close(conn, pstmt, rs);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,4 +21,8 @@ public class BoardService {
|
||||
public List<Board> 글목록보기(int page) {
|
||||
return boardDao.findAll(page);
|
||||
}
|
||||
|
||||
public int 글개수() {
|
||||
return boardDao.count();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,12 @@ public class BoardController extends HttpServlet {
|
||||
case "list" :
|
||||
int page = Integer.parseInt(request.getParameter("page"));
|
||||
List<Board> boards = boardService.글목록보기(page);
|
||||
int boardCount = boardService.글개수();
|
||||
int lastPage = (boardCount - 1) / 4;
|
||||
double currentPosition = (double)page/lastPage*100;
|
||||
request.setAttribute("boards", boards);
|
||||
request.setAttribute("lastPage", lastPage);
|
||||
request.setAttribute("currentPosition", currentPosition);
|
||||
request.getRequestDispatcher("board/list.jsp").forward(request, response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</div>
|
||||
|
||||
<div class="progress col-md-12 m-2">
|
||||
<div class="progress-bar" style="width: 70%"></div>
|
||||
<div class="progress-bar" style="width: ${currentPosition}%"></div>
|
||||
</div>
|
||||
|
||||
<c:forEach var="board" items="${boards}">
|
||||
@@ -29,8 +29,23 @@
|
||||
</c:forEach>
|
||||
<br />
|
||||
<ul class="pagination justify-content-center">
|
||||
<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>
|
||||
<c:choose>
|
||||
<c:when test="${param.page le 0}">
|
||||
<li class="page-item disabled"><a class="page-link" href="#">Previous</a></li>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<li class="page-item"><a class="page-link" href="${pageContext.request.contextPath}/board?cmd=list&page=${param.page-1}">Previous</a></li>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
<c:choose>
|
||||
<c:when test="${lastPage == param.page}">
|
||||
<li class="page-item disabled"><a class="page-link" href="#">Next</a></li>
|
||||
</c:when>
|
||||
<c:otherwise>
|
||||
<li class="page-item"><a class="page-link" href="${pageContext.request.contextPath}/board?cmd=list&page=${param.page+1}">Next</a></li>
|
||||
</c:otherwise>
|
||||
</c:choose>
|
||||
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user