1. <form> tag
Method : Only POST
Content-Type : application/x-www-form-urlencoded
HTTP Message Body를 사용하지만 형식은 Query Parameter로 전달, ex) username=hello&age=20
※ form 데이터도 메세지 바디를 통해 읽을 수 있지만, request.getParameter를 통해 읽는 것이 편리하고 주로 사용
2. Message Body
Method : POST, PUT, PATCH
JSON, XML, Text(Raw) 형식
※ GET은 URL Query Parameter 형식으로, HTTP Message Body를 사용하지 않아서 Content-Type이 없다.
1) Text
메세지 바디의 바이트코드 획득 : request.getInputStream()
바이트코드 -> String 변환 : SteramUtils.copyToString(UTF-8)
2) JSON
Content-Type : application/json
메세지 바디의 바이트코드 획득 : request.getInputStream()
바이트코드 -> String 변환 : SteramUtils.copyToString(UTF-8)
(String) JSON -> 객체 변환 : Jackson 라이브러리(ObjectMapper) 사용, obejectMapper.readValue(객체.class)
※ JSON도 결국 String 형식임
'JAVA > Spring' 카테고리의 다른 글
JUnit 테스트 정리 (0) | 2022.03.21 |
---|---|
@Annotation 정리 (0) | 2022.03.14 |
JSP View Resolver 설정 (0) | 2022.03.14 |
@Controller : 요청에 따른 Method 형식과 응답 (0) | 2022.03.14 |
Spring 뷰 폴더 위치 (0) | 2022.03.14 |