[스프링] DELETE - 글 삭제하기


삭제 버튼 만들기


read.jsp 파일에 삭제하기 버튼을 만들어주자

<a href="/board/delete?num=${data.num}" role="button" class="btn btn-outline-info">삭제하기</a>



Mapper


<!-- 게시글 삭제 -->
<delete id="delete">
    delete from springtest
    where num = #{num}
</delete>



DAO


  • DAO
public void delete(int num);
  • DAOImpl
// delete
@Override
public void delete(int num) {
    sqlSession.delete(namespace + ".delete", num);
}



Service


  • Service
public void delete(int num);
  • ServiceImpl
@Override
public void delete(int num) {
    dao.delete(num);
}



Controller


// 게시글 삭제하기
@RequestMapping(value="/delete", method = RequestMethod.GET)
public String postDelete(int num) throws Exception{
    service.delete(num);
    return "redirect:list";
}



실행하기


Categories:

Spring