[Spring JPA ] - 댓글 삭제 - 23

JEONG SUJIN·2023년 1월 10일
0

스프링부트 JPA

목록 보기
24/24

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>
profile
기록하기

0개의 댓글