hibernate Criteria中多个or和and的用法 and ( or or)

 实际中有sql如下: where   transportType=1 and ((pol=1 and pod=2) or (pol=1 and pod=3) or (pol=1 and pod=4))

Criteria criteria = getCriteria();
        if(transportType!=null)criteria.add(Restrictions.eq("transportType", transportType));
        if(polIdStr!=null && podIdStr!=null) {
            List polIdList = ListUtil.stringToList(polIdStr);
            List podIdList = ListUtil.stringToList(podIdStr);
            List CriterionList=new ArrayList();

            Disjunction dis = Restrictions.disjunction();//多个or可以拼蛸
            for(int polId:polIdList){
                for(int podId:podIdList){
                    Conjunction con=Restrictions.conjunction();//多个and拼接
                    con.add(Restrictions.eq("polId", polId));
                    con.add(Restrictions.eq("podId", podId));
                    dis.add(con);
                }
            }
            criteria.add(dis);
        }

 

你可能感兴趣的:(hibernate Criteria中多个or和and的用法 and ( or or))