메시지 띄우기
by 볼빵빵오춘기게시글 등록 수정할 때 처리 메세지를 출력해주는 걸 만들어 볼 것이다.
message.html
- controller에서 가져온 변수를 적용 시켜줘야한다.
- ${} ⇒ EL tag라고 한다.
- [[${message}]] ⇒ Controller에서 message를 받아왔다.
- alert() 문구 출력해주는 js함수이다.
- location.replace() 페이지를 이동시켜주는 함수이다.
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <script th:inline="javascript"> /* <![CDATA[*/ var message = [[${message}]]; alert(message); location.replace([[${searchUrl}]]); /* ]]> */ </script> <body> </body> </html>
cotroller
@PostMapping("/board/writepro") public String boardWritePro(Board board, Model model){ boardService.write(board); model.addAttribute("message", "글 작성이 완료되었습니다."); model.addAttribute("searchUrl", "/board/list"); return "message"; }
알 수 있는 점
message.html 하나만 만들어도 여러 개 쓸 수 있으니 url이랑 message가 변경해서 넘기면 된다.

블로그의 정보
Hello 춘기's world
볼빵빵오춘기