gpt4 book ai didi

javascript - 如何使用spring mvc接收数组作为参数?

转载 作者:行者123 更新时间:2023-12-02 10:47:15 24 4
gpt4 key购买 nike

使用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浏览器控制台传输时的参数:

enter image description here

我的 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 方法更改为 post 或使用 @RequestParameter 而不是 @RequestBody。

关于javascript - 如何使用spring mvc接收数组作为参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52465200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com