[김영한님의 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술] 회원 관리 예제 - 웹 MVC 개발 - '회원 웹 기능 - 등록' 수강
This commit is contained in:
@@ -23,4 +23,5 @@
|
|||||||
- [자바 코드로 직접 스프링 빈 등록하기](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture14.md)
|
- [자바 코드로 직접 스프링 빈 등록하기](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture14.md)
|
||||||
|
|
||||||
## 회원 관리 예제 - 웹 MVC 개발
|
## 회원 관리 예제 - 웹 MVC 개발
|
||||||
- [회원 웹 기능 - 홈 화면 추가](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture15.md)
|
- [회원 웹 기능 - 홈 화면 추가](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture15.md)
|
||||||
|
- [회원 웹 기능 - 등록](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture16.md)
|
||||||
19
SpringBoot-Introduction/Lectures/Lecture16.md
Normal file
19
SpringBoot-Introduction/Lectures/Lecture16.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
# 회원 웹 기능 - 등록
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Get방식
|
||||||
|
- `url`에서 직접 접근하는 방식
|
||||||
|
- 조회할 때 주로 사용하는 방식
|
||||||
|
- 전달(데이터 등록)할 때는 `post`방식을 주로 사용한다.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## form 태그
|
||||||
|
- 값을 입력할 수 있는 `HTML` 태그
|
||||||
|
- `method`에 `get`, `post`등을 지정한다.
|
||||||
|
- `input 태그`에서는 `name`이 서버로 넘어갈 때 `키(key)`가 된다.
|
||||||
|
- `action`에 지정된 `url`로 `post` 방식으로 값이 넘어간다.
|
||||||
|
- 값이 넘어갈 때 스프링이 알아서 `setName`을 통해서 `MemberForm`의 `name`에 값을 넣어준다(우리는 `getName`으로 꺼내면 된다).
|
||||||
|
|
||||||
|
---
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package hello.springintroduction.controller;
|
package hello.springintroduction.controller;
|
||||||
|
|
||||||
|
import hello.springintroduction.domain.Member;
|
||||||
import hello.springintroduction.service.MemberService;
|
import hello.springintroduction.service.MemberService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class MemberController {
|
public class MemberController {
|
||||||
@@ -13,4 +16,19 @@ public class MemberController {
|
|||||||
public MemberController(MemberService memberService) {
|
public MemberController(MemberService memberService) {
|
||||||
this.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:/";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<form action="/members/new" method="post">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="name">이름</label>
|
||||||
|
<input type="text" id="name" name="name" placeholder="이름을 입력하세요">
|
||||||
|
</div>
|
||||||
|
<button type="submit">등록</button>
|
||||||
|
</form>
|
||||||
|
</div> <!-- /container -->
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user