在开发前后端发送Post请求时出现的问题
@RequestMapping(value = "/login.do",method = RequestMethod.POST)
public String login(@RequestParam("id") int id,@RequestParam("name") String name) {
}
submitForm(){
//提交表单
this.$http.post('/api/test/login.do', {
id: this.login.username,
name: this.login.password
}).then(result => {
var resData=result.data;
});
}
控制台显示报错
在将后端修改后,问题解决
@RequestMapping(value = "/login.do",method = RequestMethod.POST)
public String login(@RequestBody User userGet) {
}
寻找出现此问题的原因
因为前端发送请求时的content-type为 application/json 类型
而@RequestParam 能接收的content-type为application/x-www-form-urlencoded
@RequestParam和@RequestBody 之间的区别
放上区别链接 springMVC中@RequestParam和@RequestBody之contentType
所以修改前端发送请求时的content-type亦可解决问题