使用@RequestBody
注解,标识从请求的body中取值
服务端示例代码
@ApiOperation(value="分类", notes="平台")
@RequestMapping(value="/Group",method = RequestMethod.POST,produces = "application/json")
public void CreateCataLogGroup(@RequestBody CreateCataLogGroup jsonStr,HttpServletRequest request,HttpServletResponse response){
HashMap<String, Object> resultdata = new HashMap<String, Object>();
resultdata.put("group_id", "30703304");
JSONObject json = new JSONObject();
json.put("code","A-01");
json.put("message","处理成功");
json.put("data",resultdata);
this.renderJson(response, json.toJSONString());
}
客户端请求示例,此处以postman作为客户端
这个地方尤其要注意一定要指定contentType的值为『"application/json"』 ,因为此处@RequestBody接受的是一个通过json转换的对象
如果不设置,默认为text/html,那么是支持该种类型的,会报415错误