前端axios傳遞一個包含數組的對象到后台,后台可以用String接收,也可以用List集合接收


前端代碼:

data() {
return {
listQuery: {
date: [],
}
}
},
//查詢列表信息
getList() {
if (this.listQuery.date == null || this.listQuery.date.length != 2) {
this.$message.warning("請選擇時間后查詢")
return
}
this.listLoading = true
console.log(this.listQuery) // {date:["2020-10-06","2020-11-06"]}
accDrainageQuery.getList(this.listQuery).then(res => {
this.list = res.data
this.listLoading = false
this.$refs.dataChart.list = res.data
this.$refs.dataChart.formatdata()
}).catch(err => {
console.log(err)
})
},

后端代碼:

后端用String接收,

注意:前端axios傳遞一個包含數組的對象{date:["2020-10-06","2020-11-06"]}到后台,會自動轉換成字符串2020-10-06,2020-11-06,我們再用String split[] = date.split(",")分割成字符串數組。

 

@GetMapping("/list")
public Result getList(String date) {
    return officialAccoutService.getList(date);
}
String split[] = date.split(",");

后端用List接收,

@GetMapping("/list")
public Result getList(@RequestParam List date) {

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM