您的位置:首页 > 其它

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

2017-11-20 11:37 211 查看
项目中所有的数据都是逻辑删除,在查询方案下的食谱时,可以在查询食谱时加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());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qbc