我必须将Restriction.or添加到我的标准
我在做
Criterion displayName = Restrictions.ilike("displayName", search, MatchMode.ANYWHERE);
Criterion lastUpdatedName = Restrictions.ilike("lu.displayName", search, MatchMode.ANYWHERE);
Criterion tagTokenVarText = Restrictions.ilike("tvtext.value", search, MatchMode.ANYWHERE);
Criterion tagTokenMultiText = Restrictions.ilike("tmtText.value", search, MatchMode.ANYWHERE);
Criterion tagTokenSiteVar = Restrictions.ilike("ttSiteVar.displayName", search, MatchMode.ANYWHERE);
Criterion tagMultiTokenSiteVar = Restrictions.ilike("tmtSiteVar.displayName", search, MatchMode.ANYWHERE);
Criterion or1 = Restrictions.or(displayName, lastUpdatedName);
Criterion or2 = Restrictions.or(tagTokenVarText, tagTokenMultiText);
Criterion or3 = Restrictions.or(tagTokenSiteVar, tagMultiTokenSiteVar);
Criterion or4 = Restrictions.or(or1, or2);
criteria.add(Restrictions.or(or4, or3));
但我不喜欢这种创建Criterion or1,or2 ...
的方法我的所有变量(displayName .... tagMultiTokenSiteVar)都应该是OR。我可以将它添加到列表中吗?
答案 0 :(得分:4)
使用Disjunction
:
Criteria crit = session.createCriteria(YourClass.class);
Disjunction disjunction = Restrictions.disjunction();
disjunction.add(Restrictions.ilike("lu.displayName", search, MatchMode.ANYWHERE));
// ...add others restrictions...
crit.add(disjunction);