如何解决使用Java sprintboot JAP条件构建器和或
我对CriteriaBuilder API有疑问。我是JPA的新手,我想创建(和)组合。
predicates.add(cb.equal(root.get("title"),title));
predicates.add(
cb.or(cb.between(root.get("startedAt"),startTime,endTime),cb.between(root.get("endedAt"),cb.and(
cb.greaterThanorEqualTo(root.get("endedAt").as(Date.class),cb.lessthanorEqualTo(root.get("startedAt").as(Date.class),startTime))
));
输出结果
where title = ? and (started_at between ? and ? or started_at between ? and ? or
ended_at>=? and started_at <=?)
我想要的是结果
where title = ? and (started_at between ? and ? or started_at between ? and ? or
(ended_at>=? and started_at <=?)
)
如何使用CriteriaBuilder实现这一目标?谢谢您的指教!!!
解决方法
您尝试过吗?
predicates.add(cb.and(cb.equal(root.get("title"),title),cb.or(cb.or(cb.between(root.get("startedAt"),startTime,endTime),cb.between(root.get("endedAt"),endTime)),cb.and(cb.greaterThanOrEqualTo(root.get("endedAt").as(Date.class),cb.lessThanOrEqualTo(root.get("startedAt").as(Date.class),startTime)))
));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。