程序员一代码搬运工
【Java学习心得和Java学习技术个人总结】

restrictions.or 动态添加条件

Hibernate-Restrictions用法

List<Criterion> criterions = new ArrayList<Criterion>();

				criterions.add(Restrictions.or(
						Restrictions.like("userRoles", "%"
								+ UserRole.ASSESSMENT.name() + "%"),
						Restrictions.like("userRoles",
								"%" + UserRole.SITE.name() + "%"),
						Restrictions.like("userRoles",
								"%" + UserRole.SECURITY.name() + "%"),
						Restrictions.like("userRoles",
								"%" + UserRole.TICKET.name() + "%"),
						Restrictions.like("userRoles",
								"%" + UserRole.SUPERVISOR.name() + "%"),
						Restrictions.like("userRoles",
								"%" + UserRole.SAFETYCHECK.name() + "%"),
						Restrictions.like("userRoles",
								"%" + UserRole.STAGE.name() + "%")));

Criteria criteria = session.createCriteria(Film.class);

List<Film> 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();

 

赞(0)
未经允许不得转载:程序员一代码搬运工 » restrictions.or 动态添加条件
分享到: 更多 (0)