name,
pid
from(select * from products
order by pid, id) products_sorted,
(select @pv := '1') initialisation
where find_in_set(pid, @pv)
and length(@pv := concat(@pv, ',', id))
select SYS_CONNECT_BY_PATH(列名,'>') from 表名start wITh 列名='0000000001'
connect by prior 列名(孩子列所有的列名)=列名(父列所有的列名)
这个查出来的样式如下:
000000000001>00000000>0000
不知道是不是你想要的。
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 = 0i <sizei++) {
AssetType assetType = childList.get(i)
List<AssetType>childs = assetType.getChildAssetType()
if(childs.size()>0){
list.addAll(childs)
this.findChildList(assetType, list)//递归查询节点的子节点
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)