공부하는 블로그

(웹개발) 삭제 기능 추가하기 (delete) 본문

Develop/웹개발

(웹개발) 삭제 기능 추가하기 (delete)

모아&모지리 2017. 9. 29. 11:14
1
    <a href="<c:url value='/board/delete/${boardVO.boardId}' />" onclick="deleteBoard()">삭제</a>
cs


read.jsp에 삭제를 추가한다.


1
2
3
4
5
6
7
8
    <script type="text/javascript">
    <c:if test="${sessionScope._USER_.id == boardVO.id }">
        function deleteBoard() {
            if ( confirm("이글을 정말 삭제하시겠습니까? ")) {
                    location.href="<c:url value='/board/delete/${boardVO.boardId}' />"
            }
        }
    </c:if>
cs



삭제 javascript


BoardDao 추가


BoardDaoImpl 추가


dao sql에 추가


1
2
3
4
5
6
7
     <delete id= "deleteBoard" parameterType="BoardVO">
          DELETE
          FROM    BOARD
          WHERE    BOARD_ID = ${boardId}
          AND        ID = #{id}
 
      </delete>
cs


BoardService 추가

BoardServiceImpl 추가

BoardController 추가

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@RequestMapping("/board/delete/{boardId}")
    public String doDelete(@PathVariable int boardId , HttpSession session) {
        
        MemberVO member = (MemberVO) session.getAttribute("_USER_");
        String id = member.getId();
        
        BoardVO boardVO = new BoardVO();
        boardVO.setBoardId(boardId);
        boardVO.setId(id);
        
        boolean isSuccess = boardService.deleteBoard(boardVO);
        
        return"redirect:/board/list";
    }
cs