1. Ajaxt 提交json数据到后台
$.ajax({
type:'post',
url:'apply',
/* dataType默认application/x-www-form-urlencoded key/value格式请求体*/
contentType:'application/json',
data:'{"amount":20,"chanId":"122","chanUserId":"134"}',
success:function(data){
},
error:function(){
alert('error');
}
});
2. @RequestBody注解将请求参数为json数据转换为Order对象
@RequestMapping(value = "apply",method = RequestMethod.POST)
public Order apply(@RequestBody Order order){
order = orderService.apply(order);
return order;
}
3. 使用postman进行测试
来源:oschina
链接:https://my.oschina.net/u/2706551/blog/3016550