inblog logo
|
codingb
    Spring

    v1 - 게시글 삭제하기

    coding S's avatar
    coding S
    Mar 14, 2024
    v1 - 게시글 삭제하기
    notion image
     

    1. 게시글 삭제 쿼리 작성

    @Transactional public void deleteById(int id) { Query query = em.createNativeQuery("delete from board_tb where id = ?"); query.setParameter(1, id); query.executeUpdate(); }
     

    2. 게시글 삭제 쿼리 테스트

    @Test public void deleteById_test() { //given int id = 1; //when boardNativeRepository.deleteById(id); //then List<Board> boardList = boardNativeRepository.findAll(); assertThat(boardList.size()).isEqualTo(3); }
    notion image
     

    3. 컨트롤러 delete Endpoint 만들기

    @PostMapping("/board/{id}/delete") public String delete(@PathVariable Integer id) { boardNativeRepository.deleteById(id); return "redirect:/"; }
     
    Share article

    codingb

    RSS·Powered by Inblog