Project/Study Website Project

[Spring Boot Project] 게시글 삭제 및 수정

seung_hyeon 2025. 1. 14. 21:16
  • 게시글 삭제

게시글 삭제

 

  • 게시글 버튼을 통한 삭제

삭제 버튼을 통한 삭제

 

PostView.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>게시글 상세 페이지</title>
</head>
<body>

<h1 th:text = "${post.title}">제목입니다.</h1>
<p th:text = "${post.content}">내용이 들어갈 부분입니다.</p>
<a th:href="@{/post/delete(id=${post.id})}">글 삭제</a>
</body>
</html>

 


 

  • 게시글 수정

PostController

 

@PathVariable

url에서 { }으로 감싸진 부분이 메서드 파라미터로 전달됨 (Integer, String 등)

 

url에 파라미터를 넘기는 방법

1. @PathVariable 

2. Query String

 

 

 

게시글 기존 내용 불러옴

 

 

게시글 수정 후