qs的arrayFormat与SpringBoot接收数组问题

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

失败

'brackets'

@RequestParam List

失败

'repeat'

@RequestParam List

成功

'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

失败

'brackets'

@RequestParam("tagIdList[]") List

成功

'repeat'

@RequestParam("tagIdList[]") List

失败

总结:使用List和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 不能加[]

你可能感兴趣的:(JavaWeb)