[ index.html ]
삭제버튼에
th:href="@{'/admin/pages/delete/' + ${page.id}}"
( 조심! 슬래시 / 안빠뜨리기!)
@GetMapping("/delete/{id}")
public String delete(@PathVariable int id, RedirectAttributes attr) {
pageRepo.deleteById(id);
attr.addFlashAttribute("message", "페이지가 삭제되었습니다.");
attr.addFlashAttribute("alertClass", "alert-success");
return "redirect:/admin/pages";
}
id로 삭제한다. → deleteById(id) 메서드 사용
redirect로 현재페이지에서 바로 삭제하도록
삭제 message창 뜨게 하려면 바로 삭제되어 페이지 이동없는 index.html에서 삭제 메세지창 추가할 위치에 넣기
<div th:if="${message}" th:text="${message}" th:class="${'alert '+ alertClass}"></div>
삭제 팝업창뜨는거 확인하기 -> 제이쿼리로 삭제 확인하기
1. 먼저, 삭제버튼에 class="deleteConfirm" 추가하기
2. app.js를 만든다
$('a.deleteConfirm').click(function(){
if(!confirm("페이지 삭제 하시겠습니까?")) return false;
})
- deleteConfirm클래스가 있는 a태그를 클릭했을때 함수 실행
삭제하시겠습니까? 취소 눌렀을때 true가 되어 삭제 불가.
- !확인(true) = F
- !취소(false) = T
footer 의 스크립트중 마지막 추가
<script th:src="@{/js/app.js}"></script>
Home페이지는 삭제 안되도록!
삭제버튼에
title이 Home이 아닌것만 삭제버튼 나오게 (나머지들만 삭제버튼 생성)
<a th:if="${page.title != 'Home'}">삭제</a>반응형
LIST
'Spring boot | 쇼핑몰 만들기 | 어글리 마켓 > 홈페이지 만들기 | 고객,관리자' 카테고리의 다른 글
| 카테고리 수정할때는 Model 객체를 쓴다 (0) | 2022.05.02 |
|---|---|
| 마우스로 순서 정렬 | Sorting 테이블 행 (0) | 2022.05.01 |
| 페이지 수정하기 (0) | 2022.04.30 |
| 에러나서 문자 그대로 불러올때 @ModelAttribute 와 Model 객체 차이 (0) | 2022.04.30 |
| 페이지 추가 (0) | 2022.04.30 |