728x90
@PathVariable, @RequestParam, @ModelAttribute
HTTP 요청 파라미터 - 쿼리 파라미터, HTML Form
쿼리 파라미터, HTML From 1. request.getParameter() HttpServletRequest 의 request.getParameter() 를 사용하면 다음 두가지 요청 파라미터를 조회할 수 있다. GET, 쿼리 파라미터 전송 POST, HTML Form 전송 @RequestMapping("/r
mystudylog.tistory.com
@ModelAttribute 사용시 역직렬화
요청 객체 클래스에 아래 Lombok이 없다면 역직렬화가 되지 않아 값이 제대로 들어오지 않는다.
- @AllArgsConstructor
- @NoArgsConsturctor + @Setter -> Setter가 없으면 null 로 저장
후자방법을 더 선호
이유는 기본값이 설정 가능하기 때문이다. 아래 코드 참고
@Getter
@Setter
@NoArgsConstructor
public class UserCreateRequestDto {
private String name;
private Integer age;
private String job;
private String specialty = "(empty)";
}
기본값들이 설정되어 있어서 HTTP 요청 시 해당 값이 들어오지 않는 경우엔, 기본값 설정
@RequestBody: JSON
HTTP 요청 메시지 - 텍스트, JSON
HTTP message body 데이터 조회 - text 요청 파라미터와 다르게, HTTP 메시지 바디를 통해 데이터가 직접 넘어오는 경우는 @RequestParam , @ModelAttribute 를 사용할 수 없다 1. InputStream HTTP 메시지 바디의 데이
mystudylog.tistory.com
728x90