post给后端传递数组和多个参数
·
这是前端的数据结构
data() {
return {
loading: false,
inputForm: {
id: '${gridProject.id}',
gridName: '',
gridId: '',
projectName: '',
projectId: '',
type: ''
},
data: [],
value: []
}
},
其中 gridId 和 type 是单个参数 , value 是个数组,注意 这里data中的value[]不要直接给后端传过去,需要转接下再发送过去
// 提交
doSubmit(call) {
let value = this.value
let type = this.inputForm.type
this.post('${ctx}/basicinfo/gridProject/save?gridId=' + this.inputForm.gridId + '&type=' + type, value).then((res) => {
if (res.success) {
this.$message.success(res.msg)
call()
} else {
this.$message.error(res.msg)
}
})
}
后端做接受时需要添加 @RequestBody 和 @RequestParam注解区分前端传来的数据
/**
* 保存网格项目关联信息
*
*/
@ApiOperation("保存")
@ResponseBody
@PostMapping(value = "save")
public AjaxJson save(@RequestBody @RequestParam("gridId") String gridId,@RequestBody String[] value,@RequestBody @RequestParam("type") String type) throws Exception {
gridProjectService.saveProject(gridId,value,type);
return AjaxJson.success("保存网格项目关联信息成功");
}
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)