<HTTP 요청 데이터 - GET 쿼리 파라미터>
http://localhost:8080/request-param?username=hello&age=20
#전체 파라미터 조회
request.getParameterNames().asIterator()
.forEachRemaining(paramName -> System.out.println(paramName + "="+request.getParameter(paramName)));
#단일 파라미터 조회
String username = request.getParameter("username");
System.out.println("username = " +username);
String age = request.getParameter("age");
System.out.println("age = " + age);
#이름이 같은 복수 파라미터 조회 (근데 이렇게 잘 안쓴다고 함)
http://localhost:8080/request-param?username=hello&age=20&username=good 처럼 username이 2개인 경우
String[] usernames = request.getParameterValues("username");
for(String name : usernames) {
System.out.println("username = " + name);
}
request.getParameter() 는 하나의 파라미터에 하나의 값만 있을 때 사용해야한다
파라미터에 두개 이상의 값이 있을 땐 request.getParameterValues()를 사용해야 함.
파라미터에 두개 이상이 값이 있는데 request.getParameter()를 사용하면 request.getParameterValues()의 첫번째 값을 반환함(여기선 hello를 반환)
<HTTP 요청 데이터 - API 메시지 바디 - 단순 텍스트>
HTTP 요청 데이터 메세지 바디에 내가 원하는 데이터를 직접 실어서 서버에 전송 하는 것
HTTP API에서 주로 사용 JSON,XML,TEXT
데이터 형식은 주로 JSON 사용
POST,PUT,PATCH
'공부 > Spring' 카테고리의 다른 글
[인프런]스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술_8 (0) | 2023.11.15 |
---|---|
[인프런]스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술_7 (1) | 2023.11.14 |
[인프런]스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술_5 (0) | 2023.11.08 |
[인프런]스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술_4 (0) | 2023.09.19 |
[인프런]스프링 MVC 1편 - 백엔드 웹 개발 핵심 기술_3 (0) | 2023.09.18 |