SSM框架PUT請求前端報400,415,500

白丁妄語發表於2018-03-15

問題Spring MVC設定@PutMapping前端該如何傳送請求 ?

例子:

    @ResponseBody
    @PutMapping("/update/{studentUsername}")
    public Msg updateStudent(Student student) String studentUsername){
        studentService.updateStudent(student);
        return Msg.success();
    }

前端請求:

委屈求全的解決方法:


    @ResponseBody
    @RequestMapping(value="/update/{studentUsername}",method = RequestMethod.POST)
    public Msg updateStudent(Student student,@PathVariable("studentUsername") String studentUsername){
        student.setStudentUsername(studentUsername);
        studentService.updateStudent(student);
        return Msg.success();
    }

前端請求:

reqwest({
              url: 'http://localhost:3000/student/update/'+this.props.studentUsername,
               method: 'post'
              ,type: 'json'
              ,data: this.props.form.getFieldsValue()
              ,error: function (err) {
                openNotificationWithIconError('error');
               }
              , success: function (data) {
                openNotificationWithIcon('success');
                console.log(data)
                }
            }).then((data) => {
                this.props.fetch();
            });

相關文章