检索数据的 predicate

4smxwvx5  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(322)

我使用criteriabuilder创建了一个方法来返回特定的数据。当我运行它但返回一个空列表时,它是成功的。下面是代码

public List<WeekCycleEntity> searchOnWeekCycles(String keyword) {

EntityManager em = createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<WeekCycleEntity> cq = cb.createQuery(WeekCycleEntity.class);

Root<WeekCycleEntity> weekCycleEntity = cq.from(WeekCycleEntity.class);

Predicate findName = cb.like(weekCycleEntity.get("name"), "%" + keyword + "%");
Predicate findExecutedBy = cb.like(weekCycleEntity.get("executedBy"), "%" + keyword + "%");
cq.where(findName, findExecutedBy);

TypedQuery<weekCycleEntity> query = em.createQuery(cq);
return query.getResultList();
}
jm81lzqq

jm81lzqq1#

我相信唯一的原因可能是案件不匹配,所以请尝试这个 cb.like(cb.lower(weekCycleEntity.get("name")), "%" + keyword.toLowerCase() + "%");

相关问题