1
客戶端模型當我們與他們之間的不同關係的幾個實體(如:Event --1-> Venue --*-> Rooms
)JHipster生成的Java後端,這是很好的以下內容:強類型的角
@Entity
public class Event implements Serializable {
@ManyToOne
private Venue venue;
}
@Entity
public class Venue implements Serializable {
@OneToMany(mappedBy = "venue")
private Set<Room> rooms = new HashSet<>();
}
@Entity
public class Room implements Serializable {
}
等效模型在Angular中不是那麼強類型。取而代之的是,該機型採用了BaseEntity
時,有一個關係:
export class Event implements BaseEntity {
constructor(public venue?: BaseEntity) {}
}
export class Venue implements BaseEntity {
constructor(public rooms?: BaseEntity[]) {}
}
export class Room implements BaseEntity {
constructor() {}
}
隨着打字稿,我們將高度受益於輸入這個代碼,所以我們可以對象之間導航,如:
this.event.venue.rooms;
this.event.venue.rooms[0].name;
這將是關於生成模型類別的問題,不包括BaseEntity
,但是類別本身:
export class Event implements BaseEntity {
constructor(public venue?: Venue) {}
}
export class Venue implements BaseEntity {
constructor(public rooms?: Room[]) {}
}
export class Room implements BaseEntity {
constructor() {}
}
WDYT?有沒有原因爲什麼Angular模型不像Java那樣打字?