1. SQL
1) 선택한 게시글에 대해 조회수를 1 증가 시킨다.
2. Model
1) src - model.BoardDAO.java에 updateBoardCount 추가
3.Controller
1) src - controller.ViewBoardController.java
로그인한 회원아이디와 글쓴 회원아이디를 비교하여 다르면 조회수 1 증가
1 | update board set boardCount = boardCount+1 where boardNo=1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | public void updateBoardCount( int boardNo) throws SQLException { Connection con = null ; PreparedStatement pstmt = null ; try { con = getConnection(); String sql = "update board set boardCount = boardCount+1 where boardNo=" + boardNo; System.out.println(sql); pstmt = con.prepareStatement(sql); pstmt.executeUpdate(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { closeAll(pstmt, con); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | package controller; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import model.BoardDAO; import model.ClientDTO; public class ViewBoardController implements Controller { @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession( false ); if (session== null ||session.getAttribute( "clientDTO" )== null ){ return "redirect:index.jsp" ; } ClientDTO dto = (ClientDTO) session.getAttribute( "clientDTO" ); int boardNo=Integer.parseInt(request.getParameter( "boardNo" )); HashMap<String, Object> boardInfo= BoardDAO.getInstance().viewBoard(boardNo); ClientDTO cDto = (ClientDTO)boardInfo.get( "clientDTO" ); if (!(dto.getClientId().equals(cDto.getClientId()))) BoardDAO.getInstance().updateBoardCount(boardNo); request.setAttribute( "boardInfo" , boardInfo); request.setAttribute( "url" , "/view/board/viewBoard.jsp" ); return "/view/template/home.jsp" ; } } |
'1.JAVA Web Programming > [4주차] 게시판 만들기' 카테고리의 다른 글
게시판 - webstudy-board - 게시판 글삭제 (0) | 2019.08.13 |
---|---|
게시판 - webstudy-board - 게시판 글수정 (0) | 2019.08.12 |
게시판 - webstudy-board - 게시판 글쓰기 (0) | 2019.08.12 |
게시판 - webstudy-board - 게시판 글상세 (0) | 2019.08.11 |
게시판 - webstudy-board - 게시판 글목록 (0) | 2019.08.11 |