开发者

How do I dynamically create CriteriaQuery

开发者 https://www.devze.com 2023-02-26 07:42 出处:网络
I wan开发者_如何学Ct to create equivalent CriteriaQuery to this query : select u from User u where u.name = \"John\" and u.surname = \"Black\" and u.middlename = \"Small\";

I wan开发者_如何学Ct to create equivalent CriteriaQuery to this query : select u from User u where u.name = "John" and u.surname = "Black" and u.middlename = "Small"; but I have problem with "where" predicate. Thanks


You can use:


CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery c = ...;
Root root = ...;

Predications name = builder.equal(root.get("name"), name);
Predications surname = ...;
Predications middlename = ...;

c.where(name, surname, middlename);
0

精彩评论

暂无评论...
验证码 换一张
取 消