简体   繁体   中英

I don't know why HttpMessageNotReadableException

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] .wsmsDefaultHandlerExceptionResolver : 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)]

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM