hibernate: 用Disjunction和Conjunction构造复杂的查询条件

[url]http://blog.csdn.net/whqcfp/article/details/6029061[/url]
[color=darkblue][b]Disjunction和Conjunction是逻辑或和逻辑与[/b][/color],可以用这个来构造复杂的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 = ?))
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值