小白遇坑

刚开始我是用get方法来传递json数据,但是总是报错:Required request body is missing,我人傻了,对着这个错误百度了半天,才发现,原来axios get请求方式传递给后台的参数都是字符串形式,无法传递json对象或数组对象等,犯了这么低级的错误,实在是惭愧!

axios post方式传递json数据

  1. 首先安装axios
npm run dev
  1. 在main.js中引入axios
import axios from 'axios' //引入
Vue.prototype.$axios=axios //定义为全局
  1. 在需要传值的地方使用以下代码
this.$axios({
                  url:'http://localhost:8087/creatClusterAndNodes', //此处是你向后端发送数据的地址,根据你自己的地址进行修改
                  data:this.formdata, //此处是要传递的json数据,根据你的参数进行修改
                  method:"POST",  //设置为POST请求
                  header:{
                    'Content-Type':'application/json' //规定传递的参数格式为json
                  }
                })
                  .then(res=>{
                    console.log(res.data)
                  })
                  .catch(Error=>{
                    console.log(Error)
                  })
  1. 后台接收参数
 @RequestMapping(value = "/creatClusterAndNodes", method = RequestMethod.POST, produces = "application/json;charset=UTF-8") //这里的method要设置为RequestMethod.POST
    public String creatClusterAndNodes(@RequestBody JSONObject jsonParam) {
        System.out.println("jsonParam:"+jsonParam);
        return "okk";
    }
GitHub 加速计划 / js / json
18
5
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:3 个月前 )
f06604fc * :page_facing_up: bump the copyright years Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :page_facing_up: bump the copyright years Signed-off-by: Niels Lohmann <mail@nlohmann.me> * :page_facing_up: bump the copyright years Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me> Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com> 7 天前
d23291ba * add a ci step for Json_Diagnostic_Positions Signed-off-by: Harinath Nampally <harinath922@gmail.com> * Update ci.cmake to address review comments Signed-off-by: Harinath Nampally <harinath922@gmail.com> * address review comment Signed-off-by: Harinath Nampally <harinath922@gmail.com> * fix typo in the comment Signed-off-by: Harinath Nampally <harinath922@gmail.com> * fix typos in ci.cmake Signed-off-by: Harinath Nampally <harinath922@gmail.com> * invoke the new ci step from ubuntu.yml Signed-off-by: Harinath Nampally <harinath922@gmail.com> * issue4561 - use diagnostic positions for exceptions Signed-off-by: Harinath Nampally <harinath922@gmail.com> * fix ci_test_documentation check Signed-off-by: Harinath Nampally <harinath922@gmail.com> * address review comments Signed-off-by: Harinath Nampally <harinath922@gmail.com> * fix ci check failures for unit-diagnostic-postions.cpp Signed-off-by: Harinath Nampally <harinath922@gmail.com> * improvements based on review comments Signed-off-by: Harinath Nampally <harinath922@gmail.com> * fix const correctness string Signed-off-by: Harinath Nampally <harinath922@gmail.com> * further refinements based on reviews Signed-off-by: Harinath Nampally <harinath922@gmail.com> * add one more test case for full coverage Signed-off-by: Harinath Nampally <harinath922@gmail.com> * ci check fix - add const Signed-off-by: Harinath Nampally <harinath922@gmail.com> * add unit tests for json_diagnostic_postions only Signed-off-by: Harinath Nampally <harinath922@gmail.com> * fix ci_test_diagnostics Signed-off-by: Harinath Nampally <harinath922@gmail.com> * fix ci_test_build_documentation check Signed-off-by: Harinath Nampally <harinath922@gmail.com> --------- Signed-off-by: Harinath Nampally <harinath922@gmail.com> 8 天前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐