Hello

메시지 띄우기

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가 변경해서 넘기면 된다.

 

'강의 따라하기 > board' 카테고리의 다른 글

검색 기능 1,2편  (0) 2024.01.01
페이징 처리 2편  (0) 2024.01.01
페이징 처리 1편  (0) 2024.01.01
파일 업로드  (0) 2023.12.30
board 프로젝트  (0) 2023.12.30

블로그의 정보

Hello 춘기's world

볼빵빵오춘기

활동하기