spring boot CriteriaBuilder with many in clause code example

Example 1: java jpa criteriabuilder in xample

CriteriaQuery<DeptEmployee> criteriaQuery = 
  criteriaBuilder.createQuery(DeptEmployee.class);
Root<DeptEmployee> root = criteriaQuery.from(DeptEmployee.class);
In<String> inClause = criteriaBuilder.in(root.get("title"));
for (String title : titles) {
    inClause.value(title);
}
criteriaQuery.select(root).where(inClause);

Example 2: java jpa criteriabuilder in xample

criteriaQuery.select(root)
  .where(root.get("title")
  .in(titles));

Tags:

Java Example