前端传递对象数组,后端使用list接收并解析

使用环境:前端 vue + axios,后端 springBoot
前端

save() {
    const data = [] // 图片对象数组
    data.push({
        gpGid: this.gId,
        gpAddress: this.imgList[0],
        gpIsCover: 1,
    })
    this.$axios({
        url: 'goodsPicture/save',
        method: 'post',
        dataType: 'json',
        data: JSON.stringify(data),
        headers: {
            'Content-Type': 'application/json',
        },
    }).then(res => {
        if (res.data.code === 200) {
            console.log(res.data)
        }
    })
    .catch(error => {
        console.log(error)
    })
}

后端

@PostMapping(value = "/save")
@RequiresRoles("business")
public MyResult save(@RequestBody List<GoodsPicture> goodsPictureList) {
    System.out.println("我进来了");
}

你可能感兴趣的:(springboot)