困擾了一天的問(wèn)題第二天終于解決了!
一開(kāi)始是這樣向后端傳的:(主要看后面的seats)
let list = [];
//篩選出選擇的座位排和列
info.forEach((item) => {
list.push({ row: item.row, col: item.col });
});
this.$axios.post('seat/updateEmpty?cinemaId=' + this.cinemaId +
'&hallId=' + this.hallId + '&seats=' + list).then(resp => {
if (resp.data.code == 200) {
this.seatList = resp.data.data
}
})
結(jié)果報(bào)錯(cuò)了:
在網(wǎng)上找了好多解決方法,有說(shuō)參數(shù)太長(zhǎng),超過(guò)了Tomcat的限制了怎么的,反正是沒(méi)有解決。
直接上解決方法吧。
前端代碼:
var array = [object,object,.......];
this.$axios.post(
"URL地址", array
).then((value) => {
}).catch((value) => {
this.$message.error("")
})
?后端代碼:
addList(@RequestBody List<Object> object)
最后附上我自己的:
前端代碼:
let list = [];
//篩選出選擇的座位排和列
info.forEach((item) => {
list.push({ row: item.row, col: item.col });
});
console.log(JSON.stringify(list));
this.$axios.post('seat/updateEmpty?cinemaId=' + this.cinemaId + '&hallId=' + this.hallId ,
list).
then(resp => {
if (resp.data.code == 200) {
this.seatList = resp.data.data
}
})
后端代碼:
@RequestMapping("/updateEmpty")
public Result updateEmpty(@RequestBody List<SeatRowAndCol> seats,Integer cinemaId,Integer hallId){
System.out.println("cinemaId == " + cinemaId);
System.out.println("hallId == " + hallId);
seats.forEach(item->System.out.println(item.getCol()));
System.out.println(seats);
}
終于是解決了,希望對(duì)你有幫助!
參考:vue+axios 向后端傳遞數(shù)組對(duì)象 后端使用List接收_vue向后端傳數(shù)組對(duì)象后端如何接收_java蔡徐坤的博客-CSDN博客文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-775023.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-775023.html
到了這里,關(guān)于vue+axios 向后端SpringBoot傳遞List 后端使用List接收的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!