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 不能加[]