Spring boot3 Request data

cornpip·2023년 6월 26일
0

스프링 부트

목록 보기
2/10

RequestParam

(1)
    @PostMapping("/test3")
    public String p2(@RequestParam PostRequestDto requestDto) {
        System.out.println(requestDto.toString());
        return "";
    }
(2)
    @PostMapping("/test")
    public String p(PostRequestDto requestDto) {
        System.out.println(requestDto.toString());
        return "";
    } 

application/x-www-form-urlencoded 타입 헤더에 dto로 받을 때
(1)은 못 들어오고 (2)는 잡힌다. (Dto는 setter있어야 잡힌다.)

dto아니면 (1)도 잡고 (2)도 잡는다.

public class UserSignUpDto {
    private String username;
    private String password;
    private String email;
    private boolean admin = false;
    private String adminToken = "";
}

boolean type은 true, True, tRUE 등 text만 맞게 보내면 된다.

RequestBody

    @PostMapping("/test2")
    public String g2(@RequestBody PostRequestDto requestDto) {
        System.out.println(requestDto.toString());
        return "";
    }

body의 경우 사용해야 잡힌다.

?

RequestParam이 잡는게 뭐지? (일단 쓰지 말자)

profile
https://cornpip.tistory.com 티스토리로 이전했습니다!

0개의 댓글

Powered by GraphCDN, the GraphQL CDN