jspblog : views count
This commit is contained in:
@@ -118,4 +118,24 @@ public class BoardDao {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int updateReadCount(int id) {
|
||||
String sql = "update board set readCount=readCount+1 where id =?";
|
||||
Connection conn = DB.getConnection();
|
||||
PreparedStatement pstmt = null;
|
||||
|
||||
if (conn != null) {
|
||||
try {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setInt(1, id);
|
||||
int result = pstmt.executeUpdate();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
DB.close(conn, pstmt);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ public class BoardService {
|
||||
}
|
||||
|
||||
public DetailResDto 글상세보기(int id) {
|
||||
return boardDao.findById(id);
|
||||
int result = boardDao.updateReadCount(id);
|
||||
return result == 1 ? boardDao.findById(id) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +73,14 @@ public class BoardController extends HttpServlet {
|
||||
case "detail" : {
|
||||
int id = Integer.parseInt(request.getParameter("id"));
|
||||
DetailResDto dto = boardService.글상세보기(id);
|
||||
if (dto == null) {
|
||||
Script.back(response, "상세보기에 실패하였습니다.");
|
||||
} else {
|
||||
request.setAttribute("detail", dto);
|
||||
request.getRequestDispatcher("board/detail.jsp").forward(request, response);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user