我使用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();
}
1条答案
按热度按时间jm81lzqq1#
我相信唯一的原因可能是案件不匹配,所以请尝试这个
cb.like(cb.lower(weekCycleEntity.get("name")), "%" + keyword.toLowerCase() + "%");