포스트

스프링) Spring boot Request data

스프링) Spring boot Request data

이 글은 Tistory에서 이전된 포스팅입니다. 원본은 여기에서 확인할 수 있습니다.

RequestParam

1
2
3
4
5
6
7
8
9
10
11
12
(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)도 잡는다.

1
2
3
4
5
6
7
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

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

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

?

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

이 기사는 저작권자의 CC BY-NC 4.0 라이센스를 따릅니다.