根据递归删除文件及其子文件

/** 
 * 根据pid递归删除
 * 将id删除
 * 遍历nodelist if getPid==id
 * 将其id存入数组中
 * 遍历数组 递归调用
 */
private int deleteChildren(List<TreeNode> nodeList, Long id) {
    folderMapper.delete(id);
    List<Long> ids = new ArrayList<>();
    for (TreeNode treeNode:nodeList) {
        if (treeNode.getPid().equals(id)){
            ids.add(treeNode.getId());
        }
    }
    if (ids.isEmpty()){
        return 1;
    }else{
        for (Long folderId:ids) {
            deleteChildren(nodeList, folderId);
        }
    }
    return 1;
}

你可能感兴趣的:(Java)