BoardService.java
@Transactional
public void replyDelete(int replyId) {
replyRepository.deleteById(replyId);
}
BoardApiController.java
@DeleteMapping("/api/board/{boardId}/reply/{replyId}")
public ResponseDto<Integer> replyDelete(@PathVariable int replyId){
boardService.replyDelete(replyId);
return new ResponseDto<Integer>(HttpStatus.OK.value(),1);
}
board.js
replyDelete: function(boardId, replyId) {
$.ajax({
type: "DELETE",
url: `/api/board/${boardId}/reply/${replyId}`,
contentType: "application/json; charset=utf-8",
dataType: "json"
}).done(function(resp) {
alert("댓글삭제가 완료되었슴니다.");
location.href = `/board/${boardId}`;
}).fail(function(error) {
alert(JSON.stringify(error));
});
},
detail.jsp
<button type="button" onClick="index.replyDelete(${board.id}, ${reply.id })" class="badge">삭제</button>