hibernate: 用Disjunction和Conjunction构造复杂的查询条件
2010-11-23 10:49
399 查看
Disjunction和Conjunction是逻辑或和逻辑与,可以用这个来构造复杂的SQL查询条件,实例如下:
private void CheckBsc_lj(Criteria queryCriteria)
{
Disjunction disjunction = Restrictions.disjunction();
Criterion cirterion = Restrictions.sqlRestriction("SIMULPORTCAPACITY<SIMULPORTCAPACITYOCUPIED".toLowerCase());
disjunction.add(cirterion);
cirterion = Restrictions.sqlRestriction("ADSLPORTCAPACITY<ADSLPORTCAPACITYOCCUPIED".toLowerCase());
disjunction.add(cirterion);
cirterion = Restrictions.sqlRestriction("LANPORTCAPACITY<LANPORTCAPACITYOCCUPIED".toLowerCase());
disjunction.add(cirterion);
// ONU端口,至少要录入一种端口
Conjunction conjunction = Restrictions.conjunction();
cirterion = Restrictions.eq("lanportcapacity", 0);
conjunction.add(cirterion);
cirterion = Restrictions.eq("simulportcapacity", 0);
conjunction.add(cirterion);
cirterion = Restrictions.eq("adslportcapacity", 0);
conjunction.add(cirterion);
disjunction.add(conjunction);
queryCriteria.add(disjunction);
}
构造出的条件如下:
select *
from aaaa this_
where (simulportcapacity < simulportcapacityocupied or
adslportcapacity < adslportcapacityoccupied or
lanportcapacity < lanportcapacityoccupied or
(this_.LANPORTCAPACITY = ? and this_.SIMULPORTCAPACITY = ? and
this_.ADSLPORTCAPACITY = ?))
private void CheckBsc_lj(Criteria queryCriteria)
{
Disjunction disjunction = Restrictions.disjunction();
Criterion cirterion = Restrictions.sqlRestriction("SIMULPORTCAPACITY<SIMULPORTCAPACITYOCUPIED".toLowerCase());
disjunction.add(cirterion);
cirterion = Restrictions.sqlRestriction("ADSLPORTCAPACITY<ADSLPORTCAPACITYOCCUPIED".toLowerCase());
disjunction.add(cirterion);
cirterion = Restrictions.sqlRestriction("LANPORTCAPACITY<LANPORTCAPACITYOCCUPIED".toLowerCase());
disjunction.add(cirterion);
// ONU端口,至少要录入一种端口
Conjunction conjunction = Restrictions.conjunction();
cirterion = Restrictions.eq("lanportcapacity", 0);
conjunction.add(cirterion);
cirterion = Restrictions.eq("simulportcapacity", 0);
conjunction.add(cirterion);
cirterion = Restrictions.eq("adslportcapacity", 0);
conjunction.add(cirterion);
disjunction.add(conjunction);
queryCriteria.add(disjunction);
}
构造出的条件如下:
select *
from aaaa this_
where (simulportcapacity < simulportcapacityocupied or
adslportcapacity < adslportcapacityoccupied or
lanportcapacity < lanportcapacityoccupied or
(this_.LANPORTCAPACITY = ? and this_.SIMULPORTCAPACITY = ? and
this_.ADSLPORTCAPACITY = ?))
相关文章推荐
- hibernate: 用Disjunction和Conjunction构造复杂的查询条件
- Hibernate:Disjunction&Conjunction构造复杂的查询条件
- Hibernate:Disjunction&Conjunction构造复杂的查询条件.
- Hibernate:Disjunction&Conjunction构造复杂的查询条件.
- 构造动态的多条件的复杂的正确的查询语句所采取一江湖手段(转)
- struts hibernate spring 实现分页、排序、复杂条件查询②
- Hibernate 使用Disjunction动态添加查询条件
- 使用PDF.NET数据开发框架的实体操作语言OQL构造复杂查询条件
- Hibernate-Criteria查询(3)DetachedCriteria构造查询条件、命名查询、原生SQL、调用存储过程(使用JDBC)
- gethibernatetemplate find条件查询方法
- sql 中用case when实现复杂的条件查询
- 如何结合hibernate进行复杂的查询功能设计
- Spring Data JPA 复杂/多条件组合查询
- ORM框架Hibernate多对多关联映射的HQL中的in条件查询问题
- C++标准库扩展,查找元素,使用修饰者模式构造查询条件
- hibernate各种条件查询汇总(对象、单字段、多字段等)
- Spring JPA 复杂条件查询
- hibernate入门(三)Criteria条件查询
- Hibernate入门实例——条件查询(Criteria queries)
- hibernate条件查询-----模糊查询==占位符查询