Project/IMFIND
[프로젝트] ajax 비밀 댓글 처리하기
hongchii
2021. 1. 17. 23:49
728x90
반응형
1/17
댓글 등록, 수정, 삭제를 쉽게 끝내서 그런가 오늘 아침부터 기분좋게 비댓과 대댓 만들기를 시작했다.
그러나.. 역시 쉽지 않았다...
오전시간을 다 날리고
오후부터 다시 정신을 차리고 생각이란걸 하기 시작했다.
그 결과 어느정도 흉내를 낼수가 있었다!!
본인이 작성한 댓글에만 수정/삭제 버튼이 뜨게 했고, 비밀댓글 내용은 안뜨게했다.
근데 비밀댓글만 작성이 되고 그냥 댓글을 등록하려고 하면 계속 에러가 났다;;
$('[name=commentInsertBtn]').click(function(){//댓글 등록 버튼 클릭시
console.log('진입')
if($('#Secret_Com').is(":checked") == true){
$('#Secret_Com').val('y');
var insertData = $('[name=commentInsertForm]').serialize();
alert('y');
commentInsert(insertData);
return true;
}
if($('#Secret_Com').is(":checked") == false){
$('#Secret_Com').val('n');
var insertData = $('[name=commentInsertForm]').serialize();
alert('n');
commentInsert(insertData);
return true;
}
});
작성한 코드는 대충 이런식..
"Secret_Com" checkbox가 checked면 == 'y' 아니면 == 'n'
맞는 코드인거 같았는데 이리 바꿔보고 저리바꿔봐도 계속 null이뜸..
그렇게 또 몇시간을 날리고 도움을 요청해서야 새로운 사실을 알게됐다. 충격,,
n이 null의 줄임말인줄.. ;;;;
컨트롤러에 Secret_Com == null 이면 n을 넣어주고나서야 문제가 해결됐다.
@ResponseBody
@RequestMapping(value="/comment_insert",
produces="application/json;charset=UTF-8")
private int commentInsert(LostComVO comment, HttpSession session) throws Exception{
comment.setId((String)session.getAttribute("loginUser"));
System.out.println("comment"+comment);
if ( comment.getSecret_Com() == null) {
comment.setSecret_Com("n");
}
return boardService.commentInsert(comment);
}
오늘 대댓글까지 꼭 성공하고 싶었는데 결국.. 비댓까지만 했다..후
728x90
반응형