게시물 삭제 과정은 간단하다. JPA에서 delete를 제공하기 때문이다.
//삭제
@DeleteMapping("/boards/{bno}")
public String genDelete(@PathVariable long bno) {
service.delete(bno);
return "redirect:/boards";
}
이제 ServiceProcess에 delete를 구현 해보자.
@Override
public void delete(long bno) {
repository.deleteById(bno);
}
Id인 bno(게시물 번호)를 이용하여 삭제하는 deleteById는 JPA에서 기본으로 제공하는 메서드이다.
이제 게시물 대시보드에서 삭제 버튼을 구현했다.
<form th:action="|/boards/${detail2.bno}|" method="post">
<input type="hidden" name="_method" value="DELETE">
<button>게시물 삭제</button>
</form>
'SpringBoot Project' 카테고리의 다른 글
[SpringBoot] 게시물 수정, 삭제 작성자일 때만 가능하게 하기(thymeleaf 이용) (0) | 2023.01.29 |
---|---|
[SpringBoot] 게시판 Pagination(Pageable 이용한 페이징), 리스트 불러오기 (0) | 2023.01.29 |
[SpringBoot] 게시판 게시물 조회수 기능 (0) | 2023.01.28 |