Restrictions.or多个条件用法

两个条件或查询:

Restrictions.or(Restrictions.in("username",list1),Restrictions.idEq(1));

三个或多个条件查询:(使用嵌套方式)

criteria.add(Restrictions.or(

Restrictions.in("username",list1),

Restrictions.or(Restrictions.idEq(3),Restrictions.idEq(4))

)

);



Restrictions.or(Restrictions.like(),Restrictions.or(Restrictions.like,........))
里面的or可以无限加的.还是比较好用

Session session = getHibernateTemplate().getSessionFactory()
.openSession();
Criteria criteria = session.createCriteria(Film.class);
List list = criteria.add(
Restrictions.or(Restrictions.like("description", key,MatchMode.ANYWHERE),
Restrictions.or(Restrictions.like("name", key,MatchMode.ANYWHERE),
Restrictions.or( Restrictions.like("direct", key,MatchMode.ANYWHERE),
Restrictions.or(Restrictions.like("mainplay",key,MatchMode.ANYWHERE),
Restrictions.like("filearea", key,MatchMode.ANYWHERE)))))).list();

session.close();
return list;

 

 
第二种方法
Disjunction dis=Restrictions.disjunction();  
dis.add(Restrictions.like("username", a.getUsername(),MatchMode.ANYWHERE));
dis.add(Restrictions.like("real_name", a.getUsername(),MatchMode.ANYWHERE));
criteria.add(dis); 

转载于:https://www.cnblogs.com/sdream/p/5431309.html

你可能感兴趣的:(ruby)