定制开发小程序axios发送GET请求(Content-Type)后端如何接收。

定制开发小程序自己总结可能不准确,望指教。

第一种axios({        method:'POST',        url:'http://localhost:8080/deleteTableData',        data:{          name:'小农同学。',          age:19        }      })第二种axios.post("http://localhost:8080/deleteTableData",{        name:'小农同学。',        age:19})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

上方两种请求内容都是相同的
第一种:

第二种:

上方的请求Content-Type默认都是application/json;charset=UTF-8
此时我们的后端可以这样写( @RequestBody不能省略 )

@CrossOrigin@RequestMapping(value = "/deleteTableData")public int deleteTableUpdate(@RequestBody String user) {      System.out.println(user);      输出结果为: {"name":"小农同学。","age":19}      return 0;}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

实体类的方式接收

@CrossOrigin@RequestMapping(value = "/deleteTableData")public int deleteTableUpdate(@RequestBody User user) {	 System.out.println(user);     return 0;    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

Content-Typeapplication/x-www-form-urlencoded

第一种axios({        method:'POST',        url:'http://localhost:8080/deleteTableData',        headers:{          'Content-Type':'application/x-www-form-urlencoded'        },        data:qs.stringify({name:'小农同学。',age:19},{arrayFormat: 'repeat'})      })第二种axios.post("http://localhost:8080/deleteTableData",qs.stringify(data,{arrayFormat: 'repeat'}), {     headers:{      'Content-Type': 'application/x-www-form-urlencoded'     }})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

请求内容为

后端可以使用如下接收

@CrossOrigin@RequestMapping(value = "/deleteTableData")public int deleteTableUpdate(@RequestParam("name") String name,@RequestParam("age") int age) {        System.out.println(name+","+age);        return 0;}不写注解也可以@CrossOrigin @RequestMapping(value = "/deleteTableData")public int deleteTableUpdate(String name,int age) {        System.out.println(name+","+age);        return 0;    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发