hibernate 多个or写法
if(arr != null && arr.length > 0){
Criterion c = Restrictions.like("comment", arr[0], MatchMode.ANYWHERE);
for(int i=1; i< arr.length ; i++){
c = Restrictions.or(c,Restrictions.like("comment", arr[i], MatchMode.ANYWHERE));
}
}
if(arr != null && arr.length > 0){
Criterion c = Restrictions.like("comment", arr[0], MatchMode.ANYWHERE);
for(int i=1; i< arr.length ; i++){
c = Restrictions.or(c,Restrictions.like("comment", arr[i], MatchMode.ANYWHERE));
}
}
本文介绍了一种在Hibernate中使用OR条件进行查询的方法。通过数组参数动态构建查询条件,利用Restrictions.like方法结合MatchMode.ANYWHERE实现模糊匹配,适用于评论等字段的复杂搜索场景。
12万+

被折叠的 条评论
为什么被折叠?



