vue請求后台,傳參包含List,后台接收方法


今天寫代碼的時候,后台接口接收wflxList的格式為:

@RequestParam(value = "wflxList[]", required = false) List<String> wflxList

 前端直接傳['A','B'],會報錯。網上查了沒查到解決方案。

經過同學知道,請求后台時,對參數使用qs.stringfy()方法,把參數對象格式化為一個字符串。

export function test (params) {return fxcRequest({
    url: `/test/table?${stringify(params,{arrayFormat: 'brackets'})}`,
    method: 'GET',
  })
}

按自己的目標格式進行轉換:

1、qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 輸出結果:'a[0]=b&a[1]=c'
2、qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 輸出結果:'a[]=b&a[]=c'
3、qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 輸出結果:'a=b&a=c'
4、qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'comma' })
// 輸出結果:'a=b,c'

好的,就這樣。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM