我想将FormArray保存到我的服务器春季启动

时间:2019-05-30 19:29:25

标签: angular spring-boot

<form [formGroup]="form">

<button (click)="addCreds()">Add</button>

<div formArrayName="qna" *ngFor="let creds of form.controls.qns?.value; let i = index">
  <ng-container [formGroupName]="i">
    <input  formControlName="question"><br>
    <input  formControlName="reponse1">
    <input  formControlName="reponse2">
    <input formControlName="reponse3">


  </ng-container>
</div>

<button (click)="submit()"> Enregistrer</button>

  qna:Qna;
public form: FormGroup;
 constructor(private fb: FormBuilder, private qnaService:QnaService) {
this.form = this.fb.group({
  qnas: this.fb.array([]),
});
}

addCreds() {
const creds = this.form.controls.qnas as FormArray;
creds.push(this.fb.group({
  question: new FormControl(null, Validators.required),
  reponse1: new FormControl(null, Validators.required),
  reponse2: new FormControl(null, Validators.required),
  reponse3: new FormControl(null, Validators.required),
}));
 }


 submit() {
  console.log(this.form.value);
 this.form.
 if (this.form.valid) {
 console.log('qna==============', this.form.value);
if (this.qna === undefined) {
this.qnaService.saveqna(this.form.value).subscribe( qna =>

 console.log('saved'),
 err =>
 console.log('ERROOr=$====', err)
 );
 }

}
}  
}

我想将数组从Angular保存到具有这样的json的Spring Boot

  

{       “ idQnA”:271,       “ question”:“ exemple”,       “ reponse1”:“ exemple1”,       “ reponse2”:“示例2”,       “ reponse3”:“示例3”        }

但是我总是遇到这个问题

  

{调查问卷:Array(1)}       问卷:[{...}] 0:{问题:“ d”,       回复1:“ d”,回复2:“ d”,回复3:“ d”}       长度:1__proto__:       Array(0) proto :对象

     

消息:“无法执行语句; SQL [n / a];约束[问题];嵌套异常为org.hibernate.exception.ConstraintViolationException:无法执行语句”

0 个答案:

没有答案