:클라이언트로 부터 전달받은 HTTP통신의 body부분에 있는 데이터를 자바의 객체로 만들어준다
특히, JSON데이터를 자바 객체로 만들어준다.
:RequestPart어노테이션은 JSON데이터와 파일 포함하는 멀티파트 요청에서 특정 데이터를 쉽게 처리하도록 도와준다. JSON데이터는 특정 객체에 매핑할 수 있게, 업로드 된 파일은 MultipartFIle객체로 받을 수 있게 도와주는 어노테이션
케이스 1.프론트에서 form태그를 이용해 텍스트 데이터를 전송하는 경우
@GetMapping("/form-view")
public String formView(){
return"form-view";
}
@PostMapping("/form-view")
@ResponseBody
public String formPost1(@ModelAttribute Hello hello){
System.out.println(hello);
return "ok!";
}
----------------------form-view.html---------------------------------
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Form View</title>
</head>
<body>
<form action="<http://localhost:8080/hello/form-view>" method="post" enctype="application/x-www-form-urlencoded">
**-->텍스트 만 있는 폼데이터니까 인코딩타임은 x-www, 데이터를 서버에 보내야하니까 method는 post**
이름: <input type="text" name="name">
이메일: <input type="text" name="email">
<input type="submit" value="제출">
</form>
</body>
</html>
케이스 2. 프론트에서 form태그를 이용해 텍스트+파일 데이터를 전송하는 경우