1
플레이 프레임 워크에 관계가 여러 테이블에서 데이터를 가져 오는 방법 :Ebean 나는 두 개의 서로 다른 테이블에서 가져 오는 기록으로 플레이 프레임 워크를 사용하는 방법을 모르는 내가 SQL 쿼리를
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 스칼라 템플릿이다보기를 사용, 가 먼저 지정해야 당신이 드라이버와 StoreBook에 관계가없는
@(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>
}
....
내가 쉽게 깨닫고 Play가 편해졌으며 우리가 작성한 긴 쿼리 행을 요약했습니다. 고마워요. –
그 놀이 금지 기능, Ebean ORM 기능 – dozken