728x90
question_detail.html ์ ์ญ์ ๋ฒํผ ์ถ๊ฐ
<a
onclick="return confirm('์ ๋ง๋ก ์ญ์ ํ์๊ฒ ์ต๋๊น?')"
th:href="@{|/answer/delete/${answer.id}|}"
class="delete btn btn-sm btn-outline-danger"
sec:authorize="isAuthenticated()"
th:if="${answer.author != null and #authentication.getPrincipal().getUsername() == answer.author.username}"
th:text="์ญ์ "
></a>
AnswerService
//๋ต๋ณ ์ญ์ ํ๊ธฐ
public void delete(Answer answer) {
aRepo.delete(answer);
}
AnswerController
//๋ต๋ณ ์ญ์ ์ฒ๋ฆฌ
@PreAuthorize("isAuthenticated()")
@GetMapping("/delete/{id}")
public String answerDelete(Principal principal,@PathVariable("id") int id ) {
Answer answer = aService.getAnswer(id);
if(!answer.getAuthor().getUsername().equals(principal.getName())) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,"์ญ์ ๊ถํ์ด ์์ต๋๋ค.");
}
aService.delete(answer);
return String.format("redirect:/question/detail/%s", answer.getQuestion().getId());
}

์ด ๋ต๋ณ ์ญ์ ํด๋ด

์ญ์ ํ์ธ ์๋ฃ

728x90
'BACKEND > SpringBoot' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| ์ง๋ฌธ/๋ต๋ณ ์ถ์ฒ ๊ธฐ๋ฅ (0) | 2023.11.13 |
|---|---|
| ์์ ์ผ์ ํ์ํ๊ธฐ( ์ง๋ฌธ, ๋ต๋ณ) (2) | 2023.11.13 |
| ๋ต๋ณ ์์ (0) | 2023.11.13 |
| ์ง๋ฌธ ์ญ์ ์ฒ๋ฆฌ (0) | 2023.11.10 |
| ์ง๋ฌธ ์์ ์ฒ๋ฆฌ (0) | 2023.11.10 |