From 34affd356db9f0002da30a042182f14c69ca497f Mon Sep 17 00:00:00 2001 From: banjjoknim Date: Wed, 23 Dec 2020 00:22:05 +0900 Subject: [PATCH] =?UTF-8?q?[=EA=B9=80=EC=98=81=ED=95=9C=EB=8B=98=EC=9D=98?= =?UTF-8?q?=20=EC=8A=A4=ED=94=84=EB=A7=81=20=EC=9E=85=EB=AC=B8=20-=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=A1=9C=20=EB=B0=B0=EC=9A=B0=EB=8A=94=20?= =?UTF-8?q?=EC=8A=A4=ED=94=84=EB=A7=81=20=EB=B6=80=ED=8A=B8,=20=EC=9B=B9?= =?UTF-8?q?=20MVC,=20DB=20=EC=A0=91=EA=B7=BC=20=EA=B8=B0=EC=88=A0]=20?= =?UTF-8?q?=ED=9A=8C=EC=9B=90=20=EA=B4=80=EB=A6=AC=20=EC=98=88=EC=A0=9C=20?= =?UTF-8?q?-=20=EC=9B=B9=20MVC=20=EA=B0=9C=EB=B0=9C=20-=20'=ED=9A=8C?= =?UTF-8?q?=EC=9B=90=20=EC=9B=B9=20=EA=B8=B0=EB=8A=A5=20-=20=EB=93=B1?= =?UTF-8?q?=EB=A1=9D'=20=EC=88=98=EA=B0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpringBoot-Introduction/Lectures/Contents.md | 3 ++- SpringBoot-Introduction/Lectures/Lecture16.md | 19 +++++++++++++++++++ .../controller/MemberController.java | 18 ++++++++++++++++++ .../controller/MemberForm.java | 13 +++++++++++++ .../templates/members/createMemberForm.html | 14 ++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 SpringBoot-Introduction/Lectures/Lecture16.md create mode 100644 SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberForm.java create mode 100644 SpringBoot-Introduction/src/main/resources/templates/members/createMemberForm.html diff --git a/SpringBoot-Introduction/Lectures/Contents.md b/SpringBoot-Introduction/Lectures/Contents.md index 5d3629f..16d8b6c 100644 --- a/SpringBoot-Introduction/Lectures/Contents.md +++ b/SpringBoot-Introduction/Lectures/Contents.md @@ -23,4 +23,5 @@ - [자바 코드로 직접 스프링 빈 등록하기](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture14.md) ## 회원 관리 예제 - 웹 MVC 개발 -- [회원 웹 기능 - 홈 화면 추가](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture15.md) \ No newline at end of file +- [회원 웹 기능 - 홈 화면 추가](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture15.md) +- [회원 웹 기능 - 등록](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture16.md) \ No newline at end of file diff --git a/SpringBoot-Introduction/Lectures/Lecture16.md b/SpringBoot-Introduction/Lectures/Lecture16.md new file mode 100644 index 0000000..5e1723e --- /dev/null +++ b/SpringBoot-Introduction/Lectures/Lecture16.md @@ -0,0 +1,19 @@ +# 회원 웹 기능 - 등록 + +--- + +## Get방식 +- `url`에서 직접 접근하는 방식 +- 조회할 때 주로 사용하는 방식 +- 전달(데이터 등록)할 때는 `post`방식을 주로 사용한다. + +--- + +## form 태그 +- 값을 입력할 수 있는 `HTML` 태그 +- `method`에 `get`, `post`등을 지정한다. +- `input 태그`에서는 `name`이 서버로 넘어갈 때 `키(key)`가 된다. +- `action`에 지정된 `url`로 `post` 방식으로 값이 넘어간다. +- 값이 넘어갈 때 스프링이 알아서 `setName`을 통해서 `MemberForm`의 `name`에 값을 넣어준다(우리는 `getName`으로 꺼내면 된다). + +--- \ No newline at end of file diff --git a/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java b/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java index d876aa4..e8eb31e 100644 --- a/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java +++ b/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java @@ -1,8 +1,11 @@ package hello.springintroduction.controller; +import hello.springintroduction.domain.Member; import hello.springintroduction.service.MemberService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; @Controller public class MemberController { @@ -13,4 +16,19 @@ public class MemberController { public MemberController(MemberService memberService) { this.memberService = memberService; } + + @GetMapping("/members/new") + public String createForm() { + return "members/createMemberForm"; + } + + @PostMapping("/members/new") + public String create(MemberForm form) { + Member member = new Member(); + member.setName(form.getName()); + + memberService.join(member); + + return "redirect:/"; + } } diff --git a/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberForm.java b/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberForm.java new file mode 100644 index 0000000..0808118 --- /dev/null +++ b/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberForm.java @@ -0,0 +1,13 @@ +package hello.springintroduction.controller; + +public class MemberForm { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/SpringBoot-Introduction/src/main/resources/templates/members/createMemberForm.html b/SpringBoot-Introduction/src/main/resources/templates/members/createMemberForm.html new file mode 100644 index 0000000..c0353f2 --- /dev/null +++ b/SpringBoot-Introduction/src/main/resources/templates/members/createMemberForm.html @@ -0,0 +1,14 @@ + + + +
+
+
+ + +
+ +
+
+ + \ No newline at end of file