问题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();
});