如何使用Spring MVC接收数组作为参数?

时间:2018-09-23 10:27:40

标签: javascript java spring spring-mvc vue.js

使用.htaccess将数组对象转换为json字符串

JSON.stringify

使用Chrome浏览器控制台进行传输时的参数:

enter image description here

我的商品管理员类,例如:

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");
    }
}

Spring mvc无法接收数组。或者我在编写axios代码时遇到问题吗?如何解决?

1 个答案:

答案 0 :(得分:1)

根据您的请求,

axios.get('http://localhost/goods', json)

这是一个获取请求。所以它不会有身体。

您可以尝试将get方法更改为发布或使用@RequestParameter而不是@RequestBody。