TIL)23.08.30(Requestparam, ModelAttribute,RequestPart)

주민·2023년 8월 30일
0

TIL

목록 보기
75/84

@Requestparam

url에 담긴 query string(쿼리 스트링)에 담긴 값을 변수에 담을 수 있다.

( @RequestParam("title") String title, 
@RequestParam("content") String content )

@ModelAttribute

HTTP Body 내용과 HTTP 파라미터의 값들을 Getter, Setter, 생성자를 통해 주입하기 위해 사용한다.
일반 변수의 경우 전달이 불가능하기 때문에 model 객체를 통해서 전달해야 한다.

( @ModelAttribute("test") Test test )
-----------------------------------
public class Test{
	private String title
    private String content
}

@RequestPart

json 문자열은 자동으로 VO로 컨버팅되고 MultipartFile도 잘 받아지기 때문에 application/json + multipart/form-data 를 파라미터로 받아야 할 경우에 사용한다.

(@RequestPart(value = "file", required = false) MultipartFile file,
@RequestPart(value = "requestDto") PostRequestDto postRequestDto)

0개의 댓글

관련 채용 정보