0
這聽起來很複雜但很難在標題中表達。 這是我的常見情況,也可能是其他情況。假設我們有一個Car實體和CarType實體。 CarType很簡單,並有ID,名稱,這幾乎都是。使用中間表映射實體屬性到另一個表的列
class CarType{
private long id;
private String carName;
private String description; //not important - just to ensure
private String costValue; //not important - that we need separate CarType entity
.....
}
實體租車
class Car{
private long id;
private String carNumber;
@ManyToOne //ManyToOne using extra table
private CarType carType;
.....
}
這是常見的情況。並且在汽車的網頁上也有常見的情況。 需要大量的代碼來渲染來自Car實體的數據(使用jsp或特別是通過json ajax請求發送汽車列表)。編碼並不困難,但是在json ajax請求的情況下,js可能很大。
問題是,大部分時間我只需要知道cartype.carName。其餘的領域只是幫手,實際上它們是可視化的。
如何額外的輔助實體映射領域:
class CarTable{ // entity map to same db table as Car entity
private long id;
private String carName;
**//here mapping which i dont know how to implement**
private String carType;
}
這並不重要,但對我來說這是經常的情況,這就需要日常的工作要做無論是在服務器端預處理,無論是在JSP處理,或者在js後期處理中。
如果有人有什麼想法,分享或知道回答