@GetMapping("/modify/{id}")
public String reviewModify(@PathVariable("id") Integer id, Model model){
Book book = this.bookService.getBookById(id);
Review review = this.reviewService.getReview(id);
model.addAttribute("book",book);
model.addAttribute("review", review);
return "book/review_modify_form";
}
@PostMapping("/modify/{id}")
public String reviewModify(@PathVariable("id") Integer id,@Valid ReviewForm reviewForm, BindingResult bindingResult, Principal principal){
if (bindingResult.hasErrors()) {
return "book/book_detail";
}
Review review = this.reviewService.getReview(id);
this.reviewService.modify(review, reviewForm.getContent());
return String.format("redirect:/book/detail/%s",review.getBook().getId());
}```
코드를 입력하세요
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h5 class="my-3 border-bottom pb-2">리뷰수정</h5>
<form th:object="${reviewForm}" method="post">
<input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
<div class="mb-3">
<label for="content" class="form-label">내용</label>
<textarea name="content" id="content" class="form-control" rows="10"></textarea>
</div>
<input type="submit" value="저장하기" class="btn btn-primary my-2">
</form>
</body>
</html>```
코드를 입력하세요
<div class="book_bottom-section">
<!-- 리뷰 등록 폼 -->
<div class="mb-3">
<label for="content" class="form-label"></label>
<form th:action="@{|/review/create/${book.id}|}" method="post">
<textarea name="content" id="content" class="form-control" rows="3"></textarea>
<button type="submit" class="btn btn-sm btn-primary" style="width: 100px; margin-top: 5px;">리뷰등록</button>
</form>
</div>
<!-- 리뷰 목록 -->
<div class="a_comment_top">
<ul th:each="review : ${reviewList}">
<li>
<div class="review-box mb-2">
<div>
<span th:text="${review.author.username}"></span>
<div class="create-date" th:text="${#temporals.format(review.createDate, 'yyyy-MM-dd HH:mm')}"></div>
</div>
<div class="review-content">
<span th:text="${review.content}"></span>
</div>
<a th:href="@{|/review/delete/${review.id}|}" class="btn btn-sm btn-primary" style="width: 100px; margin-right:10px;">삭제</a>
<!-- <a th:href="@{|/review/modify/${review.id}|}" class="btn btn-sm btn-primary" style="width: 100px; margin-right:10px;" >수정</a>-->
</div>
</li>
</ul>
</div>
<button id="toggleInput">입력 칸 보이기/닫기</button>
<div id="inputContainer" style="display: none;">
<input type="text" id="textInput">
<button id="submitInput">제출</button>
</div>
<script>
// 버튼 클릭 이벤트 핸들러
document.getElementById("toggleInput").addEventListener("click", function() {
var inputContainer = document.getElementById("inputContainer");
if (inputContainer.style.display === "none") {
inputContainer.style.display = "block"; // 보이기
} else {
inputContainer.style.display = "none"; // 닫기
}
});
</script>