使用 JSON.stringify
将数组对象转换为 json 字符串
var array = [1, 2];
let json = JSON.stringify(array);
console.log(json);
axios.get('http://localhost/goods', json).then(function (res) {
if (res.code == 200) {
console.log("ok");
}
}
使用 Chrome 浏览器控制台传输时的参数:

我的 cargo Controller 类,例如:
@RequestMapping(value = "goods",method = RequestMethod.GET)
public String deleteByIds(@RequestBody Integer[] ids) {
goodsService.deleteByIds(ids);
return "ok";
}
Spring mvc 接收不到数组,还是我写 axios 代码有问题?如何解决?
最佳答案
根据您的要求,
axios.get('http://localhost/goods', json)
这是一个获取请求。所以它不会有 body 。
您可以尝试将 get 方法更改为发布或使用@RequestParameter 而不是@RequestBody。
关于javascript - 如何使用spring mvc接收数组作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52465200/