mysql怎么查询树形结构的所有上级,你这个问题是怎么解决的?求指导_百 ...
发布网友
发布时间:2022-04-26 11:49
我来回答
共1个回答
热心网友
时间:2022-04-07 16:16
java版的实际例子。类同你说的情况
private void findChildList(AssetType parent,List<AssetType> list){
String hql = "from AssetType a where a.parentAssetType.assetTypeId=? ORDER BY a.sort,a.assetTypeName asc";
List<AssetType> 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<AssetType> childs = assetType.getChildAssetType();
if(childs.size()>0){
list.addAll(childs);
this.findChildList(assetType, list);//递归查询节点的子节点
}