vue+springboot使用数组传输信息
- 后端扔过来一个接口参数需要用数组,下面给一个自己使用的方法吧。
- 批量删除和单个删除都使用了这个接口。

1、前端案例代码
<el-table-column label="操作">
<template slot-scope="scope">
<el-button
size="mini"
type="danger"
@click="delCustomer(scope.row.identity)">删除
</el-button>
</template>
</el-table-column>
<el-button type="danger" size="mini" @click="delCustomer(null)">批量删除</el-button>
1、2 js部分
npm i qs
import qs from 'qs';
data() {
return {
customerList: [],
multipleSelection: [],
}
},
methods: {
delCustomer(cids) {
var that = this
let ids = [];
if (this.multipleSelection.length != 0) {
var multipleSelection = this.multipleSelection;
for (var i = 0; i < multipleSelection.length; i++) {
ids.push(multipleSelection[i].identity)
}
}
if (cids != null) {
ids.push(cids);
}
var a = qs.stringify({ids: ids}, {arrayFormat: 'repeat'})
this.$http.post(`/back/customer/deleteCustomerByIds`, a).then(function (response) {
that.initCustomer();
that.$message.success(response.data.msg);
})
},
}
2、后端案例代码
2、1 controller
@RestController
@RequestMapping("/back/customer")
@Api(tags="客户管理")
@CrossOrigin
public class CustomerController {
@Autowired
private CustomerService customerService;
@PostMapping("deleteCustomerByIds")
public CommonResult deleteCustomerByIds(@RequestParam List<String > ids){
System.out.println("customer=="+ Arrays.asList(ids));
return customerService.deleteCustomerByIds(ids);
}
}
2、2 service实现层
@Override
public CommonResult deleteCustomerByIds(@RequestParam List<String> ids) {
int i = customerDao.deleteBatchIds(ids);
return new CommonResult(2000,"删除成功",i);
}