qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘indices‘})
//形式: ids[0]=1&aids1]=2&ids[2]=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘brackets‘})
//形式:ids[]=1&ids[]=2&ids[]=3
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘repeat‘})
//形式: ids=1&ids=2&id=3
对比:
前端arrayFormat | 后台SpringBoot | 接收结果 |
'indices' | @RequestParam List<Long> | 失败 |
'brackets' | @RequestParam List<Long> | 失败 |
'repeat' | @RequestParam List<Long> | 成功 |
'indices' | @RequestParam Long[] | 失败 |
'brackets' | @RequestParam Long[] | 失败 |
'repeat' | @RequestParam Long[] | 成功 |
'indices' | @RequestParam("tagIdList[]") Long[] | 失败 |
'brackets' | @RequestParam("tagIdList[]") Long[] | 成功 |
'repeat' | @RequestParam("tagIdList[]") Long[] | 失败 |
'indices' | @RequestParam("tagIdList[]") List<Long> | 失败 |
'brackets' | @RequestParam("tagIdList[]") List<Long> | 成功 |
'repeat' | @RequestParam("tagIdList[]") List<Long> | 失败 |
总结:使用List<Long>和Long[]是没有区别的,区别在于@RequestParam中是否加[]
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘indices‘})
//形式: ids[0]=1&aids[1]=2&ids[2]=3 @RequestParam无法接收
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘brackets‘})
//形式:ids[]=1&ids[]=2&ids[]=3 要加[]
qs.stringify({ids: [1, 2, 3]}, {arrayFormat: ‘repeat‘})
//形式: ids=1&ids=2&ids=3 不能加[]