在 Spring Boot Rest API 中,我能夠避免使用@JsonIgnore. 在郵遞員結果中,相關串列(多方)顯示為空。當我在 Angular 中使用這個端點時,即使@JsonIgnore我的郵遞員跳過它,我是否能夠顯示該相關串列?
考慮Matiere和PlannificationConcours之間的關系,它有一些其他孩子,如何避免無限回圈和回傳null值。
一側
@Data
@AllArgsConstructor
@Table(name="Matiere")
public class Matiere extends Audit<String> implements Serializable {
@Column(name="ID", nullable=false, length=10)
@Id
@GeneratedValue(generator="PNU_MATIERE_ID_GENERATOR")
@org.hibernate.annotations.GenericGenerator(name="PNU_MATIERE_ID_GENERATOR", strategy="native")
private int id;
// @ManyToOne(targetEntity=fdsa.edu.PNUFDSA.Model.Matiere.class, fetch=FetchType.LAZY)
// @org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.LOCK})
// @JoinColumns(value={ @JoinColumn(name="MatiereID", referencedColumnName="ID", nullable=false) }, foreignKey=@ForeignKey(name="Pre-requis"))
// private fdsa.edu.PNUFDSA.Model.Matiere matiere;
@Column(name="Description", nullable=true, length=255)
private String description;
@Column(name="Code", nullable=true, length=255)
private String code;
@Column(name="Contenu", nullable=true, length=255)
private String Contenu;
@Column(name="NombreDeCreditStandard", nullable=false, length=10)
private int nombreDeCreditStandard;
@OneToMany(mappedBy="matiere", targetEntity= Cours.class)
private List<Cours> cours ;
@JsonManagedReference
@OneToMany(mappedBy="matiere", targetEntity= PlannificationConcours.class)
private List<PlannificationConcours> plannificationConcourses;
public Matiere() {
}
多方
@Entity
@AllArgsConstructor
@Table(name="PlannificationConcours")
public class PlannificationConcours extends Audit<String> implements Serializable {
public PlannificationConcours() {
}
@Column(name="ID", nullable=false, length=10)
@Id
@GeneratedValue(generator="PNU_PLANNIFICATIONCONCOURS_ID_GENERATOR")
@org.hibernate.annotations.GenericGenerator(name="PNU_PLANNIFICATIONCONCOURS_ID_GENERATOR", strategy="native")
private int id;
@ManyToOne (targetEntity= Concours.class, fetch=FetchType.LAZY)
@JoinColumns(value={ @JoinColumn(name="concoursId", referencedColumnName="ID", nullable=true) }, foreignKey=@ForeignKey(name="ConcoursPlanificationConcours"))
//@JsonBackReference
private Concours concours;
@JsonBackReference
@ManyToOne(targetEntity= Matiere.class, fetch=FetchType.LAZY)
@JoinColumns(value={ @JoinColumn(name="MatiereId", referencedColumnName="ID", nullable=true) }, foreignKey=@ForeignKey(name="MatierePlanificationConcours"))
private Matiere matiere;
@Column(name="`Date`", nullable=true)
@Temporal(TemporalType.DATE)
private java.util.Date Date;
@Column(name="Quotation", nullable=false, length=10)
private double quotation;
@Column(name="NoteDePassage", nullable=false, length=10)
private double noteDePassage;
@OneToMany(mappedBy="plannificationConcours", cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity= HistoriqueExamenConcours.class)
private List<HistoriqueExamenConcours> historiqueExamenConcours;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Concours getConcours() {
return concours;
}
public void setConcours(Concours concours) {
this.concours = concours;
}
public Matiere getMatiere() {
return matiere;
}
public void setMatiere(Matiere matiere) {
this.matiere = matiere;
}
public java.util.Date getDate() {
return Date;
}
public void setDate(java.util.Date date) {
Date = date;
}
public double getQuotation() {
return quotation;
}
public void setQuotation(double quotation) {
this.quotation = quotation;
}
public double getNoteDePassage() {
return noteDePassage;
}
public void setNoteDePassage(double noteDePassage) {
this.noteDePassage = noteDePassage;
}
public List<HistoriqueExamenConcours> getHistoriqueExamenConcours() {
return historiqueExamenConcours;
}
public void setHistoriqueExamenConcours(List<HistoriqueExamenConcours> historiqueExamenConcours) {
this.historiqueExamenConcours = historiqueExamenConcours;
}
}
郵遞員回復
"id": 2,
"description": "Prgrammation C#",
"code": "C Sharp",
"nombreDeCreditStandard": 2,
"cours": [],
"contenu": "C#",
"plannificationConcours": null
}```
uj5u.com熱心網友回復:
您必須首先了解您的前端(Angular)和后端(Spring Boot)是兩個獨立的應用程式。
我能夠通過@JsonIgnore 避免無限回圈。在郵遞員結果中,相關串列(多方)顯示為空。
因此,您已通過修改回傳物件轉換為 JSON 物件的方式來修改后端,以免進入不定式回圈。在您的后端在轉換為 JSON 物件時會陷入不定式回圈的情況下,現在將在此時寫入空值以避免不定式回圈。
當我將在 Angular 中使用此端點時,即使在我的郵遞員中被 @JsonIgnore 跳過,我是否能夠顯示該相關串列
您的 Angular 應用程式將收到郵遞員收到的確切資訊,這是您后端的答復。所以答案是否定的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/379578.html
上一篇:多個物體中的地址物體而不指定它
