gpt4 book ai didi

playframework - 使用 Ebean 和 Play 框架将条件放在列表字段上

转载 作者:行者123 更新时间:2023-12-02 01:30:52 24 4
gpt4 key购买 nike

我有一个 Device 类和一个 Event 类,如下所示:

    @Entity
public class Device extends Model {

@Id
public Long id;

@OneToMany(mappedBy = "device")
public List<Event> events = new ArrayList<Event>();

...
}

@Entity
public class Event extends Model {

@Id
public Long id;

@Constraints.Required
@Formats.DateTime(pattern = "dd-MM-yyyy HH:mm")
public Date start;

@Formats.DateTime(pattern = "dd-MM-yyyy HH:mm")
public Date end;

@ManyToOne
public Device device;

...

}

我想获取在给定的 Date fromDate to 之间没有事件的所有设备的列表(实际上是页面)。听起来很简单,但我无法使用 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);

最佳答案

.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 日期。

关于playframework - 使用 Ebean 和 Play 框架将条件放在列表字段上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34251250/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com