Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
先查询第一层的数据,然后调用递归循环第一层的数据,查询父Id等于第一层的Id,执行完成后第一层一下的所有数据就全部查询出来了。。。
public List<Information> getTreeList(Integer topId) {
String hql="from Information where isDelete=2 and id="+topId;
List<Information> entityList=baseDao.queryHQL(hql);
entityList.addAll(getSubList(entityList));
return entityList;
}
private List<Information> getSubList(List<Information> entityList) {
for (int i = 0; i < entityList.size(); i++) {
String hql="from Information where isDelete=2 and fatherId="+entityList.get(i).getId();
if(baseDao.queryHQL(hql).size()>0){
List<Information> list2=baseDao.queryHQL(hql);
entityList.get(i).setList(list2);
getSubList(entityList.get(i).getList());
}
}
return entityList;
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/193548.html原文链接:https://javaforall.net
