定制开发小程序自己总结可能不准确,望指教。
第一种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-Type为application/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