Play 中的链接查询!框架

发布于 2024-12-18 13:55:16 字数 586 浏览 4 评论 0原文

有没有办法在“Play!”中链接查询框架而不是手动编写查询?

像这样的东西:

模型 m = Model.where("姓名","比尔").where("性别","米").first();

我想知道,因为我最近从 Codeigniter + dmz 切换到 grails然后现在到“玩!”并且有点失望与上述框架相比的查询链接

PS:我显然不是在谈论 fetch()from() 方法。

is there a way to chain queries in the "Play!" framework instead of manually writing a query ?

Something like:

Model m = Model.where("name","Bill").where("gender","m").first();

I wonder because I recently switched from Codeigniter + dmz to grails then now to "Play!" and have been a bit disappointed by the queries chaining compared to the framework mentioned above

PS: I'm obviously not talking about the fetch() and the from() methods.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

复古式 2024-12-25 13:55:16

有一个 JpqlSelect 对象可以用来做

public static Model findBill() {
    JpqlSelect select = new JpqlSelect().from("Model").where("name=?").param("Bill").andWhere("gender=?").param("m");
    return find(select.toString(), select.getParams().toArray()).first();
}

这个帮助器还远未完成,但它可能适合您的需求

There is a JpqlSelect object with wich you can do

public static Model findBill() {
    JpqlSelect select = new JpqlSelect().from("Model").where("name=?").param("Bill").andWhere("gender=?").param("m");
    return find(select.toString(), select.getParams().toArray()).first();
}

This helper is far from being complete but it may suits your needs

赠佳期 2024-12-25 13:55:16

您可以使用 java.persistence Criteria API 来完成此操作,

CriteriaQuery q = JPA.em().getCriteriaBuilder().createQuery(Model.class)
q.where(<Expression>).where(<Expression>);
TypedQuery<Model> tq = JPA.em().createQuery(q);
List<Model> result = tq.getResultList();

如下所示:此处 和此处作为开始

You can do it with java.persistence Criteria API like that:

CriteriaQuery q = JPA.em().getCriteriaBuilder().createQuery(Model.class)
q.where(<Expression>).where(<Expression>);
TypedQuery<Model> tq = JPA.em().createQuery(q);
List<Model> result = tq.getResultList();

Look here and here for start

携君以终年 2024-12-25 13:55:16

另一种选择是使用 http://www.querydsl.com/ 及其 jpa 集成。

An other option could be using http://www.querydsl.com/ with it's jpa integration.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文