vue发送数组到后台
arrayFormat四个属性[indices、brackets、repeat、comma],默认为indices1.arrayFormat = 'indices'//ids[0]=1&ids[1]=2&ids[2]=3&ids[3]=42.arrayFormat = 'brackets'//ids[]=1&ids[]=2&ids[]=3&ids[]
·
arrayFormat四个属性[indices、brackets、repeat、comma],默认为indices
1.arrayFormat = 'indices' //ids[0]=1&ids[1]=2&ids[2]=3&ids[3]=4
2.arrayFormat = 'brackets' //ids[]=1&ids[]=2&ids[]=3&ids[]=4
3.arrayFormat = 'repeat' //ids=1&ids=2&ids=3&ids=4
4.arrayFormat = 'comma' //ids=1,2,3,4
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);//ids = [1, 2, 3, 4]
}
@DeleteMapping(value = "/testDelete")
public void testDelete(@RequestParam("ids") List<String> ids) {
System.out.println("ids = " + ids);//ids = [1, 2, 3, 4]
}
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);//ids = [1, 2, 3, 4]
}
@PutMapping(value = "/testPut")
public void testPut(@RequestParam("ids") List<String> ids) {
System.out.println("ids = " + ids);//ids = [1, 2, 3, 4]
}
更多推荐
已为社区贡献2条内容
所有评论(0)