Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 코드스쿼드
- 잃어버린 괄호
- 알고리즘데이
- spring-boot
- 코드스쿼드 마스터즈
- 2021.01.11
- SWEA
- algorithm
- 2021.01.17
- 2021.01.22
- baekjoon1541
- 2021.01.19
- 자바
- 박재성
- 2021.01.21
- 백준 9093
- java
- 2021.01.14
- 2021.01.12
- 2021.01.06
- 쉽게 배우는 운영체제
- 백준 1149
- 알고리즘
- 괄호
- 마스터즈 2주차 회고
- Til
- 2021.01.18
- 2020.01.08
- 2021.01.13
- 백준
Archives
- Today
- Total
Cooper's devlog
2-2. 회원가입 기능 구현 본문
2-2. 회원가입 기능 구현
1. 강의 링크(박재성님)
https://www.youtube.com/watch?v=UQ2wPndQ4-0&list=PLqaSEyuwXkSppQAjwjXZgKkjWbFoUdNXC&index=10
2. 학습 내용
- GET/POST에 대한 초간단 설명
- User 클래스 추가 및 setter 메소드를 통한 자동 매핑
3. 과정
(1) submit을 할 때, form tag를 사용한다.
(2)controller을 생성
client에서 데이터를 전달해주고 싶다면 input tag의 name과 controller의 매개인자 이름과 같게 설정되어 있어야 한다.
-> 만약 인자가 너무 많다면 class를 하나 더 생성해서 만들어 주도록 하자.
<static/form.html>
- form action → /create 요청을 하겠다.
- method → post(요청 값을 url에 공개하지 않겠다) ==> localhost:8787/create 끝.
- input tag의 name과 User객체의 변수와 이름이 같아야 mapping이 가능!!
<User.java>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package net.slipp.web;
public class User {
private String UserId;
private String password;
private String name;
private String email;
public void setUserId(String userId) {
UserId = userId;
}
public void setPassword(String password) {
this.password = password;
}
public void setName(String name) {
this.name = name;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return "User [UserId=" + UserId + ", password=" + password + ", name=" + name + ", email=" + email + "]";
}
}
|
<userController.java>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
package net.slipp.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
@Controller
public class UserController {
@PostMapping("/create")
public String create(User user) {
System.out.println("user: " + user);
return "index";
}
}
|
cs |
- form method : post방식이었으므로, PostMapping으로 선언해서 사용하자.
- input tag의 name과 User객체의 변수와 이름이 같아야 mapping이 가능하다.
'Programming > Spring-boot' 카테고리의 다른 글
2-5. 이전 상태로 원복 후 반복 연습 (0) | 2020.07.11 |
---|---|
2-3. 사용자 목록 기능 구현 (0) | 2020.07.10 |
2-1. mustache 활용한 동적인HTML과 MVC 설명 (0) | 2020.07.10 |
2-0. 두 번째 반복주기 학습목표 및 과정 설명 (0) | 2020.07.09 |
1-3. local 소스 코드를 github에 올리기 (0) | 2020.07.07 |
Comments