qbc关联查询出对象集合,对集合中的对象进行条件过滤

来源:互联网 发布:新浪微博抱歉网络繁忙 编辑:程序博客网 时间:2024/06/07 13:29

项目中所有的数据都是逻辑删除,在查询方案下的食谱时,可以在查询食谱时加qbc条件进行过滤,对于食谱下的食谱详情需要将未删除的食谱查出后,对食谱的集合进行迭代,然后将不符合的食谱详情移除。代码如下:

    //根据系统方案id查询方案的食谱import java.util.Iterator;        @Override    public List<SystemSchemeRecipes> findBySystemSchemeIdAndStatus(Integer systemSchemeId) {        try {            Criteria criteria = dao.createCriteria();            criteria.add((Restrictions.eq("scheme.sysSchemeId", systemSchemeId)));            criteria.add((Restrictions.eq("recipesStatus", 0)));            //查询出的所有的未删除的食谱集合            List<SystemSchemeRecipes> recippesList1 =criteria.list();            if (recippesList1.size() > 0) {                for (int i = 0; i < recippesList1.size(); i++) {                    //将查出的食谱详情集合放入迭代器中,进行遍历,判断如果状态为删除,则将其从返回集合中移除                    Iterator<SystemSchemeRecipesInfo> iter = recippesList1.get(i).getSystemschemeRecipesInfos().iterator();                    while (iter.hasNext()) {                        if (iter.next().getRecipesStatus() != 0) {                            iter.remove();                        }                    }                }            }            return recippesList1;        } catch (Exception e) {            e.printStackTrace();            log.error(e.getMessage());            throw new BasicRuntimeException(this, "根据系统方案id查询方案的食谱异常"                    + e.getMessage());        }    }
原创粉丝点击