2015-12-13 104 views
3

我有一個Device類和Event類像這樣把條件對列表場在給定的Date fromDate to之間。還有聽起來很簡單,但我有點不能讓我想用Ebean什麼,這是我怎麼想應該工作,但我得到的設備不正確,使用Ebean和播放框架

Model.Finder<Long, Device> find = new Model.Finder<>(Long.class, Device.class); 
    Page<Device> devicePage = find.where() 
     .or(
      Expr.lt("events.end", from), 
      Expr.gt("events.start", to) 
     ) 
     .orderBy("id asc") 
     .findPagingList(10) 
     .setFetchAhead(false) 
     .getPage(0); 

回答

2
.or(
    Expr.and(
     Expr.lt("events.start", from), 
     Expr.lt("events.end", from) 
    ), 
    Expr.and(
     Expr.gt("events.start", to), 
     Expr.gt("events.end", to) 
    ) 
) 

的理念是:事件的開始&結束日期必須小於FROM日期或必須大於END日期。

+0

很好,這不幸的是不能正常工作 – behzad