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

标签 javascript java spring spring-mvc vue.js

使用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/

相关文章:

java - 在 spring 中以编程方式将类的实例绑定(bind)到限定符

javascript - react Hook : accessing state across functions without changing event handler function references

javascript - v-model 并选择多个

java - 在主函数中使用超出范围的变量

java - Apache Camel - 拆分和聚合 - 旧交换始终为空

java - 如何在 spring junit 测试中禁用日志记录(错误除外)?

javascript - 在代理数组上调用 concat 会引发错误

javascript - 如何在 HERE JS 3.1 API 中更改 map 标记的 anchor ?

java - Android - 精确的数学计算

java - maven会改变我的项目的名称,如何阻止它?