错误:org.springframework.web.HttpMediaTypeNotSupportedException:内容类型“不支持”

时间:2019-06-11 17:19:51

标签: java reactjs spring-boot

我正在使用后端进行Java spring-boot开发,并使用前端进行React js开发项目。所以我遇到了这样的错误

org.springframework.web.HttpMediaTypeNotSupportedException: Content type '' not supported我试图改变消费量,但不幸的是,它没有帮助。*

有什么想法吗? 谢谢

这是客户端

  handlePasswordUpdate(event) {
    event.preventDefault();
    swal.fire({
        title: 'Password Update',
        showCancelButton: true,
        focusConfirm: false,
        html: '<div class="form-group"><input id="currentPasswordId" type="password" class="form-control" placeholder="Current password" name="currentPassword"/></div>' +
            '<div class="form-group"><input id="newPasswordId" type="password" class="form-control" placeholder="New password" name="newPassword"/></div>' +
            '<div class="form-group"><input id="confirmNewPasswordId" type="password" class="form-control" placeholder="Confirm password" name="confirmNewPassword"/></div>',
        preConfirm: () => [
            document.querySelector('#currentPasswordId').value,
            document.querySelector('#newPasswordId').value,
            document.querySelector('#confirmNewPasswordId').value
        ]
    }).then((results) => {
        var index_0 = results.value[0];
        var index_1 = results.value[1];
        var index_2 = results.value[2];

        if (index_1 === index_2) {
            let resultObject = {
                username: this.state.email,
                currentPassword: index_0,
                newPassword: index_1,
                confirmNewPassword: index_2
            };
            console.log(this.state.email);
            var param = {
                "method": "PUT",
                "url": "http://localhost:8080/v1/users/profile/password",
                "headers": {
                    "content-type": "application/json",
                    "authorization": "Bearer  " + sessionStorage.getItem("token")
                }
            };

            axios(param, resultObject).then((res) => {
                console.log(res);
            }).catch((err) => {
                console.log(err);
            });

        } else {
            console.log("off");
        }
    });

}

这是服务器端

 @RequestMapping(method = RequestMethod.PUT, value = "/users/profile/password", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
public void updateUserPassword(@AuthenticationPrincipal(errorOnInvalidType = true) Principal principal,
                               @Valid @RequestBody PasswordChangeRequest passwordChangeRequest) {
    passwordChangeRequest.checkPasswordMatch();

    userPasswordService.updatePassword(principal.getUsername(), passwordChangeRequest.getCurrentPassword(),
            passwordChangeRequest.getNewPassword(), passwordChangeRequest.getConfirmNewPassword());
}

0 个答案:

没有答案