0
votes

I don't know why this code error

i testing PostMan It works fine

but this js code not work

Javascript

chkStudentNum : function() {
        const jsonData = {
            studentNum : $('#studentNum').val()
        };
        console.log(JSON.stringify(jsonData));
        $.ajax({
            url: '/idcheck',
            contentType: 'application/json; charset=utf-8',
            method : 'GET',
            data: JSON.stringify(jsonData)
        }).done(function(data, status, jqXHR) {

            if (data == true) {
                signUp.chkSignUpInfo();
            } else {

            }
        }).fail(function() {

        });
    }

RestController

@GetMapping("/idcheck")
    public boolean studentNumChk(@RequestBody MemberStudentNumChkDto dto) {
        System.out.println(dto.getStudentNum());
        if(dto.getStudentNum() == null) {
            //throws Exception
        }
        return memberService.studentNumChk(dto);
    }

MemberStudnetNumChkDto

@Getter
@Setter
@NoArgsConstructor
public class MemberStudentNumChkDto {
    private String studentNum;

    public Member toEntity() {
        return Member.builder()
                .studentNum(studentNum)
                .build();
    }

    @Builder
    public MemberStudentNumChkDto(String studentNum) {
        this.studentNum = studentNum;
    }
}

Error 2020-03-23 21:33:46.495 WARN 26976 --- [nio-8080-exec-7] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public boolean com.services.webservice.controller.SignInUp.SignRestController.studentNumChk(com.services.webservice.service.dto.SignUp.MemberStudentNumChkDto)]

1

1 Answers

0
votes

Your endpoint expects a @RequestBody but is declared as a GET endpoint (via @GetMapping).

You should probably change it to a @PostMapping.

See Does Spring @RequestBody support the GET method?