无法获得实体

时间:2019-06-21 10:55:24

标签: angular angular6

我有那两个课:

学生* --- 1地址

export class Student
{
    id: number;
    firstName: string;
    adresse: Adresse;
}

export class Adresse
{
    id: number;
    email: string;
    phone: string;
    town: string;
    city: string;
}

我要从 list-student.component.ts

中选择一名学生
<table class="table">
      <thead>
        <tr>
          <th>Id</th>
          <th>Name</th>
          <th>Update</th>
        </tr>
      </thead>
      <tbody *ngIf="!loader">
        <tr *ngFor="let student of userbs | async" style="width: 1500px;">
          <td>{{student.id}}</td>
          <td>{{student.name}}</td>
          <td><span class="button is-small btn-warning" (click)='editUser(student)'>Update</span></td>
        </tr>
      </tbody>
    </table>

和函数editUser是在 modify-student.component.ts 内部定义的,如下所示:

 editUser(student: Student): void
    {
        console.log("--------------Student's adress: " + -->  It gives the error.
        console.log("--------------Student's name: " + student.name);  -->  It gives the expected name for Example AJT_82 or Adrita.

        this.router.navigate(['modify-student']);
    };

在尝试恢复console.log上学生的电子邮件时出现此错误。

  

错误TypeError:“ student.adresse未定义”

This is the console

感谢@ AJT_82先生和@Adrita夫人,我知道问题的原因。 出现此错误是由于消耗了后端的Rest服务(Spring Boot)。我添加了注释

@JsonIgnore 
private Adresse adresse; 

这就是为什么在邮递员上,我无法向学生展示地址对象。 这就是为什么我对@JsonIgnore引起的地址不确定的原因。 但这会由于消除@JsonIgnore

而在Spring Boot中引起另一个异常。
  

com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25)   〜[jackson-databind-2.9.6.jar:2.9.6]。

您是否对解决该问题有任何想法? 非常感谢。

1 个答案:

答案 0 :(得分:0)

请您确保Student和Adresse的映射是单向的。 HTH。

相关问题