使用 jpa 的 Criteria API 比較日期

Compare Date entities in JPA Criteria API

CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<MessageSendInfo> criteriaQuery = criteriaBuilder.createQuery(Person.class);
Root<Person> root = criteriaQuery.from(Person.class);
criteriaQuery.select(root);
Predicate restrictions = criteriaBuilder.conjunction();
// date conditon >= 當前時間
restrictions = criteriaBuilder.and(restrictions, criteriaBuilder.greaterThanOrEqualTo(root.<Date>get("sendDate"), new Date()));

reference

Compare Date entities in JPA Criteria API

JPA find entities where date is between start and end date that can be null using Criteria

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章