简体   繁体   English

如何在 angular 中将属性作为数组发送到后端 spring 启动

[英]how to send property as a array to backend spring boot in angular

I have the following method with which I am trying to send to my backend some values as a list.我有以下方法,我试图将一些值作为列表发送到我的后端。 the accepted json format is as follows:接受的 json 格式如下:

{
value: [xyz]
}

But right now I am sending just the xyz part to my backend as a single value but I need to send it as the shown part.但现在我只将 xyz 部分作为单个值发送到我的后端,但我需要将它作为所示部分发送。 mine looks like this: xyz according to the payload sent to the backend in network in my console.我的看起来像这样: xyz 根据在我的控制台中发送到网络后端的有效负载。

this is my function I am using to send these to my backend:这是我用来将这些发送到后端的 function:

 setValueForTest() {
    this.personArray = this.form.controls.selectBox.value;
    this.personArraySave = []
    this.personArray.forEach((id) => {
        this.personArraySave.push(id)
        this.api.setValueForPerson({
          body: id
        
        ).subscribe(response => {
          console.log(response)
        });
      }
    });
  } 

the body and personArraySave is from type Person which only has id: Array as attribute body 和 personArraySave 来自只有 id: Array 作为属性的 Person 类型

I imagine api.setValueForPerson is a service that sends the data, if yes, maybe you can send the data something like this我想 api.setValueForPerson 是一个发送数据的服务,如果是的话,也许你可以发送这样的数据

setValueForPerson(person:Person):Observable<any>{
   return this.httpCLient.post<any>(yourURL, {value:person});
}

Thanks for everyone who helped, the problem is fixed I just instanced an Element of the Object I am sending.感谢所有提供帮助的人,问题已解决我刚刚实例化了我发送的 Object 的一个元素。 Then I could work with the array element inside that model and push my values inside it.然后我可以使用 model 内部的数组元素并将我的值推入其中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM