满意答案
cabin319
2015.11.28
采纳率:48% 等级:7
已帮助:562人
java版的实际例子。类同你说的情况
private void findChildList(AssetType parent,List list){
String hql = "from AssetType a where a.parentAssetType.assetTypeId=? ORDER BY a.sort,a.assetTypeName asc";
List childList = this.assetTypeDao
.getEntityManager()
.createQuery(hql)
.setParameter(1, parent.getAssetTypeId())
.getResultList();
int size = childList.size();
if(size>0){
for (int i = 0; i < size; i++) {
AssetType assetType = childList.get(i);
List childs = assetType.getChildAssetType();
if(childs.size()>0){
list.addAll(childs);
this.findChildList(assetType, list);//递归查询节点的子节点
}
}
}
}
00分享举报