0
に私は、3つのリストと2つのオペレータOP1と、「OR」することができOP2を取得「AND」、「AND NOT」..私はこの問題はDetachedCriteriaを
のようなクエリを形成する必要があることでしょう例えば、テーブルの従業員を考慮し、私は二つの方法
public List<Employee> getRequestedEmployee(List<Long> list1 , List<Long> list2, List<Long> list3 , String op1 , String op2) {
DetachedCriteria dc = DetachedCriteria.forClass(Employee)
if (!CollectionUtils.isEmpty(list1))
{
dc.add(Restrictions.in(list1,emp_id));
}
if(!CollectionUtils.isEmpty(list3)
{
dc = getCriteria(dc , list2 , op1);
}
if(!CollectionUtils.isEmpty(list3)
{
dc = getCriteria(dc , list3 , op2);
}
}
private DetachedCriteria getCriteria(DetachedCriteria dc , List<long> empIdList, String operator)
{
if(!CollectionUtils.IsEmpty(empIdList))
{
if("and".equals(operator))
{
Conjunction andOp = Restrictions.Conjunction();
andOp.add(Restrictions.in(empIdList));
dc.add(andOp);
}
else if("or".equals(operator))
{
Disjunction orOp = restrictions.disjunction();
orOp.add(Restrictions.in(empIdList))
dc.add(andOp);
}
else
{
dc.add(Restrictions.not(empIdList));
}
return dc;
}
}
を書かれている3つのリストのList1、リスト2、EMP_IDの
select emp_num , emp_dpt , emp_name
from employee
where
emp_id in (list1)
op1
emp_id in (list2)
op2
emp_id in (list3)
のLIST3を取得することがあります。..場合は、これまで私は、論理和との問題に直面しています過ぎ去っているまたはそれはop1 = and
、op2 = or
を渡していた場合、それはこの
select emp_num , emp_dpt , emp_name
from employee
where
emp_id in (list1)
and
emp_id in (list2)
and
emp_id in (list3)
ように形成するが、私は何をしたいことは
select emp_num , emp_dpt , emp_name
from employee
where
emp_id in (list1)
and
emp_id in (list2)
or
emp_id in (list3)
これまでは期待してい
かです例えば
をとして解釈し、..されます置いて、op1またはop2に関係なく
助けが必要です...