我有这两门课:
学生***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
上恢复学生的电子邮件时遇到此错误。
ERROR TypeError: "student.adresse is undefined"
感谢@AJT_82 先生和@Adrita 女士,我知道了问题的原因。 出现此错误是由于使用后端(Spring Boot)的休息服务。我添加注释
@JsonIgnore
private Adresse adresse;
这就是为什么在 postman 上,我无法显示学生内部的地址对象。
这就是为什么我因 @JsonIgnore
导致地址未定义。
但这会导致 Spring Boot 上的另一个异常,因为消除了 @JsonIgnore
,即
com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) ~[jackson-databind-2.9.6.jar:2.9.6].
您对解决这个问题有什么想法吗? 非常感谢。
最佳答案
请确保Student和Adresse的映射是单向的。 HTH。
关于angular - 无法获取实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56702052/