조회수는 컨트롤러에서 하지 않고 Service와 Store에서 해결한다.
Service
@Override
public Board printOneVyNo(Integer boardNo) {
Board board = bStore.selectOnbyNo(boardNo, session);
int result = 0 ;
if(board != null) {
result = bStore.updateBoardCoaunt(session, boardNo);
}
return board;
}
- 디테일로 연결되는 메소드 안에 count를 증가할수있는 메소드를 추가한다.
Store
@Override
public int updateBoardCoaunt(SqlSessionTemplate session, int boardNo) {
int result = session.update("BoardMapper.updateBoardCount", boardNo);
return result;
}
- 스토어에서 mapper를통해 카운터를 증가하게 하는 쿼리문을 db에 연결시킨다.
Mapper
<update id="updateBoardCount">
update board_tbl set BOARD_COUNT = BOARD_COUNT+1 where board_no = #{boardNo}
</update>
- 해당 쿼리문을 통해 디테일 페이지에 접속할때마다 count가 1씩 증가된다.