Hibernate QBC组合查询例子
Criteria criteria = session.createCriteria(Employee.class); //1. AND: 使用Conjunction表示 //Conjunction 本身就是一个Criterion对象 //且其中还可以添加Criterion对象 Conjunction conjunction = Restrictions.conjunction(); conjunction.add(Restrictions.like("name", "a", MatchMode.ANYWHERE)); Department dept = new Department(); dept.setId(80); conjunction.add(Restrictions.eq("eq", dept)); System.out.println(conjunction); //2: OR Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.ge("salary", 6000F)); disjunction.add(Restrictions.isNull("email")); criteria.add(disjunction); criteria.add(conjunction); criteria.list();
结果:
... where (this_.SALARY >= ? or this_.EMAIL is null) and (this_.NAME like ? and this_.DEPT_ID = ?)
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。