1
我有一個SQL查詢關係的多個表中的數據,我不知道我可以通過讀取記錄來自兩個不同的表用它玩框架:Ebean如何獲取從在遊戲框架
SELECT a.Id as DriverId, a.names as Drivernames, b.bill_no as driverBillNumber, b.DriverId from drivers a join StoreBook b on a.Id = b.DriverId where a.phone_number ='9889'
我有兩個mysql表drivers
和Storebook
。我能夠從StoreBook表中獲取數據列表,但無法訪問驅動程序表進行加入。
看看我的代碼:
@Entity
@Table(name = "StoreBook")
public class Store extends Model {
@Id
public Long id;
@Constraints.Required
public String bill_no;
public int amount;
public String Created_at;
public static Model.Finder<Long, Store> find = new Finder(Long.class, Store.class);
public static List<Store> mystore() {
return find.all();
}
}
驅動程序表:
@Entity
@Table(name ="drivers")
public class New_driver extends Model{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "Id", updatable = false, nullable = false)
public Long Id;
@Column
@Constraints.Required
public String names;
New_driver(String names) {
this.names = names;
}
public static void create(New_driver account) {
account.save();
}
}
下面的代碼在控制器中使用:
public class showBooks_history extends Controller {
public static Result(){
Form<StoreBook> result = form(StoreBook.class);
return ok(showbooks.render(StoreBook.mystore(), result));
}
}
代碼我使用的觀點是HTML模板斯卡拉:
@(formList: List[Store],form: Form[Store]))
@main_dashboard("welcome")
{
.....
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Driver names</th>
<th>Bill number</th>
</tr>
</thead>
<tbody>
@for(i <- Store.mystore()) {
<tr>
<td><i>names ???</i></td>
<td><i>@i.bill_no</i></td>
</tr>
}
....
之後,我意識到輕鬆和總結我們編寫的SQL查詢的長長的一行。非常感謝你 –
它的非播放功能,它的Ebean ORM的功能 – dozken