Spring boot @RequestBody数据传递过程详解
这篇文章主要介绍了Springboot@RequestBody数据传递过程详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
@RequestBody需要接的参数是一个string化的json
@RequestBody,要读取的数据在请求体里,所以要发post请求,还要将Content-Type设置为application/json
java的api
参数为JSONObject,获取到的参数处理
@PostMapping("/combine") publicResultcombine(@RequestBodyJSONObjectjsonParam){ System.out.println(jsonParam.toJSONString()); System.out.println(jsonParam.get("fileName")); ArrayListll=(ArrayList)jsonParam.get("ops"); for(inti=0;i(1)js调用
vardispatchesDTO={"fileName":"E:/java/project/ppt/data/tmpTest.pptx","ops":[["E:/java/project/ppt/data/test1.pptx","1,2,9"],["E:/java/project/ppt/data/Threejs动画.pptx","1"],["E:/java/project/ppt/data/系统时间和实时天气.pptx","1"]]}; $.ajax({ type:"post", contentType:"application/json", url:"http://localhost:8080/api/ppt/combine", data:JSON.stringify(dispatchesDTO), success:function(data){ console.log(data); } });(2)php的curl调用
"E:/java/project/ppt/data/tmp.pptx", "ops"=>[['E:/java/project/ppt/data/test1.pptx','1,2,9'], ['E:/java/project/ppt/data/test1.pptx','2'], ], ]; $data_string=json_encode($aa); curl_setopt($curl,CURLOPT_CUSTOMREQUEST,"POST"); curl_setopt($curl,CURLOPT_POSTFIELDS,$data_string); curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); curl_setopt($curl,CURLOPT_HTTPHEADER,array( 'Content-Type:application/json', 'Content-Length:'.strlen($data_string), )); //执行命令 $data=curl_exec($curl); //关闭URL请求 curl_close($curl); //显示获得的数据 print_r($data);(3)postman调用
参数
{"fileName":"E:/java/project/ppt/data/tmpTest.pptx","ops":[["E:/java/project/ppt/data/test1.pptx","1,2,9"],["E:/java/project/ppt/data/Threejs动画.pptx","1"]]}以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。