Hibernate:Disjunction&Conjunction构造复杂的查询条件.

Hibernate:Disjunction&Conjunction构造复杂的查询条件

Disjunction和Conjunction是逻辑或和逻辑与,如下:

用来组合一组逻辑或【or】条件的方法

1.Restrictions.disjunction();

用来组合一组逻辑与【and】条件的方法

2.Restrictions.conjunction();


实例一:构造复杂的SQL查询条件

private void CheckBsc_lj(Criteria queryCriteria) 
 {
  Disjunction disjunction = Restrictions.disjunction();
  Criterion cirterion = Restrictions.sqlRestriction("SIMULPORTCAPACITY

实例二:构造模糊查询

        Disjunction dis=Restrictions.disjunction();   
        dis.add(Restrictions.like("chanpin", "冰箱", MatchMode.ANYWHERE));   
        dis.add(Restrictions.like("chanpin", "洗衣机", MatchMode.ANYWHERE));   
        dis.add(Restrictions.like("chanpin", "热水器", MatchMode.ANYWHERE));   
        dis.add(Restrictions.like("chanpin", "空调", MatchMode.ANYWHERE));   
        detachedCriteria.add(dis);




你可能感兴趣的:(java)