기본적으로 많이 쓰는 메서드❗️
get : 서버에서 데이터를 가져올 떄
post : 서버로 데이터를 밀어낼 때
UserController
추가@RestController
@RequestMapping("/user")
public class UserController {
@PostMapping("/post")
public void post(@RequestBody Map<String, Object> requestData) {
requestData.entrySet().forEach(stringObjectEntry -> {
System.out.println("key : " + stringObjectEntry.getKey()
+ "value : " + stringObjectEntry.getValue());
});
}
@PostMapping("/post-object")
public void postObject(@RequestBody PostUserRequest requestData) {
System.out.println("Test POST OBJECT");
System.out.println(requestData.toString());
}
}
PostUserRequest
추가public class PostUserRequest {
private String id;
private String name;
private String email;
private String address;
private String password;
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@Override
public String toString() {
return "PostUserRequest{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
", email='" + email + '\'' +
", address='" + address + '\'' +
", password='" + password + '\'' +
", phoneNumber='" + phoneNumber + '\'' +
'}';
}
@JsonProperty("phone_number")
private String phoneNumber;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
Talend 에서 request 보내면
짜잔!