1. Model
* 짚고 넘어갈 뽀인트
- delete문 작성
1) content.xml
<delete id="delete" parameterType="int">
<![CDATA[
DELETE FROM pcomment
WHERE cno = #{cno}
]]>
</delete>
2) contentDAO.java
public int commentDelete(int cno) throws Exception {
return sqlSession.delete("comment.delete", cno);
} // delete() end
2. View
* 짚고 넘어갈 뽀인트
- 댓글 수정 버튼을 누르면 댓글 내용 칸이 input 폼으로 바뀌며 원래 써져있던 댓글 내용이 출력.
- 수정시 commentUpdateProc 함수 호출.
- 자바스크립트에서는 if문이 한줄이라면 중괄호( { , } ) 를 생략해도 된단다!(이게 뭐야!!)
// 댓글 삭제
function commentDelete(cno){
$.ajax({
url:"/comment/delete/"+cno
,type:"post"
,success:function(data){
if(data==1) {commentList()};
}
}); // ajax() end
} // commentDelete() end
3. Controller
* 짚고 넘어갈 뽀인트
- update 명령어 생성
- 댓글의 번호인 cno와 새로 수정될 본문 내용 content를 DTO로 저장하고 넘겨준다.
@RequestMapping("/delete/{cno}")
@ResponseBody
private int mCommentServiceDelete(@PathVariable int cno) throws Exception {
return commentDao.commentDelete(cno);
} // mCommentServiceDelete() end
'⁂ MyBatis Framework > : 기본 익히기' 카테고리의 다른 글
[MyBatis] #5-3 AJAX를 활용한 댓글 게시판 만들기 3 - 댓글 목록 보기(select) (0) | 2022.11.14 |
---|---|
[MyBatis] #5-2 AJAX를 활용한 댓글 게시판 만들기 2 - 댓글 등록(Insert) (0) | 2022.11.14 |
[MyBatis] #5-1 AJAX를 활용한 댓글 게시판 만들기 1 - 테이블, DTO, DAO, Controller 생성 (0) | 2022.11.14 |
[MyBatis3] #4-8 파일 업로드 및 댓글 게시판 만들기 : 수정 기능 넣기 (0) | 2022.11.11 |
[MyBatis3] #4-7 파일 업로드 및 댓글 게시판 만들기 : 삭제 기능 넣기 (0) | 2022.11.11 |