Java – querydsl query parameters?
•
Java
Using JPA, we have the namedquery witch. Let's pass the parameters in this way:
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 wonder if there is a similar method to pass parameters later using querydsl?
Solution
I use the following methods in 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"));
Adjusting the code to statically generated querydsl beans should be trivial
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
