arrayFormat四个属性[indices、brackets、repeat、comma],默认为indices
1.arrayFormat = 'indices'
2.arrayFormat = 'brackets'
3.arrayFormat = 'repeat'
4.arrayFormat = 'comma'
1.GET、DELETE请求发送数组到后台
前台
let arrays = [1, 2, 3, 4]
const data = qs.stringify({ids: arrays}, {
arrayFormat: 'comma'
})
axios.get('http://127.0.0.1:8109/testGet', {params: this.$qs.parse(data)})
axios.delete('http://127.0.0.1:8109/testDelete', {params: this.$qs.parse(data)})
后台
@GetMapping(value = "/testGet")
public void testGet(@RequestParam(value = "ids") List<String> ids) {
System.out.println("ids = " + ids);
}
@DeleteMapping(value = "/testDelete")
public void testDelete(@RequestParam("ids") List<String> ids) {
System.out.println("ids = " + ids);
}
2.POST、PUT请求发送数组到后台
前台
let arrays = [1, 2, 3, 4]
const data = qs.stringify({ids: arrays}, {
arrayFormat: 'comma'
})
axios.post('http://127.0.0.1:8109/testPost', data)
axios.put('http://127.0.0.1:8109/testPut', data)
后台
@PostMapping(value = "/testPost")
public void testPost(@RequestParam(value = "ids") List<String> ids) {
System.out.println("ids = " + ids);
}
@PutMapping(value = "/testPut")
public void testPut(@RequestParam("ids") List<String> ids) {
System.out.println("ids = " + ids);
}
|