처음 만드는 Spring Boot 메모장

edit.html 수정버튼

· 2 views

수정 화면에서는 사용자가 제목이나 내용을 변경한 뒤, 그 내용을 저장할 수 있어야 합니다.
이를 위해 입력 폼 하단에 "수정" 버튼을 추가하고, 이 버튼을 클릭하면 서버에 수정 요청을 보내도록 설정합니다.

▼ Code

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title></title>
  <link rel="stylesheet" href="/css/main.css"​>
</head>
<body>
  <form name="form1" method="post" action="/update">
    <input type="hidden" name="id" th:value="${memo.id}​">
    제목: 
    <input type="text" id="title" name="title" th:value="${memo.tit​le}" required>
    <br>
    내용: <br>
    <textarea id="content" name="content" rows="8" cols="80" th:text="${memo.cont​ent}" required></textarea>
    <br>
    <button type="submit">수정</bu​tton>
    <button type="button" onclick="location.hr​ef='/'">목록</button>
  </form>
</body>
</html>

▼ Explain

<form name="form1" method="post" action="/update">
메모를 수정할 때 사용되는 form 태그입니다.
method="post"는 폼 데이터를 POST 방식으로 전송하겠다는 의미입니다.
action="/update"는 수정된 데이터를 서버의 /update 경로로 전송하겠다는 의미입니다.

<input type="hidden" name="id" th:value="${memo.id}​">
이 줄은 메모의 고유 번호(id)를 서버로 함께 전송하기 위한 숨은 입력(hidden input)입니다.

사용자는 이 값을 화면에서 볼 수 없지만, 서버는 이 값을 통해 어떤 메모를 수정할 것인지 식별합니다.
th:value="${memo.id}​"는 타임리프 문법으로, 컨트롤러에서 전달받은 메모의 id 값을 자동으로 채워줍니다.

<button type="submit">수정</bu​tton>
사용자가 클릭하면 폼에 입력된 제목과 내용, 그리고 숨겨진 id 값이 함께 서버로 전송됩니다.
type="submit"이므로 이 버튼을 누르면 폼 전체가 POST /update 경로로 제출됩니다.
이후 컨트롤러에서 이 데이터를 받아 데이터베이스를 업데이트하게 됩니다.

이렇게 구성하면 사용자가 메모 내용을 수정한 뒤, "수정" 버튼을 눌러 저장할 수 있는 완전한 폼이 완성됩니다.

댓글

아직 댓글이 없습니다.