简体   繁体   English

QueryDsl查询参数?

[英]QueryDsl queries with parameters?

With jpa we have the NamedQuery witch alow us to pass the parameters later this way: 使用jpa,我们有NamedQuery女巫让我们以这种方式传递参数:

public <T2> T2 getSingleResult(String namedQuery, Map<String, String> parameters, Class<T2> clazz) {

    TypedQuery<T2> typedQuery = entityManager.createNamedQuery(namedQuery, clazz);
    for (Entry<String, String> parameter : parameters.entrySet()) {
        typedQuery.setParameter(parameter.getKey(), parameter.getValue());
    }
    return typedQuery.getSingleResult();
}

So I want to know, is there a similar way to pass parameters later with QueryDsl? 所以我想知道,有没有类似的方法稍后使用QueryDsl传递参数?

I use the following approach with PathBuilder: 我在PathBuilder中使用以下方法:

PathBuilder pathBuilder = new PathBuilder(Object.class, "my_table");
SQLQuery query = new SQLQuery(connection, OracleTemplates.DEFAULT);
query.from(pathBuilder.getRoot())
    .where(pathBuilder.get("my_column").eq(new Param(String.class, "param1")))
    .set(new Param(String.class, "param1"), "67")
    .list(pathBuilder.get("my_column"));

That should be trivial to adapt the code to static generated QueryDSL beans. 将代码调整为静态生成的QueryDSL bean应该是微不足道的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM