There are two ways:
1. Manual conversion
Define the conversion method:
converToUrl(requestParams){
let params = [];
Object.entries(requestParams).forEach(([key, value]) => {
let param = key + '=' + value;
params.push(param);
});
return '?' + params.join('&');
},
The usage is as follows:
let param = {
ids: [1,2,3,4] };
var converParam = this.converToUrl(param);
Then add this parameter directly after the URL link:
api.url + converParam
2. Through the qs plugin
// 在项目中使用命令行工具输入
npm install qs
// 引入qs插件
import qs from 'qs'
The usage is as follows:
let param = {
ids: [1,2,3,4] };
var converParam = qs.stringify(param, {
arrayFormat: 'repeat' });
Add a ? after the URL link can
api.url + '?' + converParam
The backend can receive directly through the following methods:
@GetMapping("/delete")
@ApiOperation("删除")
public CommonResult<Boolean> delete(@RequestParam("ids") List<Long> ids) {
return success(true);
}