第一次修改

master
小萌新 4 months ago
parent 3b2394b77d
commit ee50cd8316
  1. 12
      src/main/java/com/teaching/backend/service/impl/chapter/ChapterServiceImpl.java

@ -154,10 +154,10 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
@Override @Override
public List<Chapter> getChapterTree(String courseId) { public List<Chapter> getChapterTree(String courseId) {
System.out.println(courseId);
List<Chapter> chapters=baseMapper.selectSectionsByCourseId(courseId); List<Chapter> chapters=baseMapper.selectSectionsByCourseId(courseId);
System.out.println(chapters);
Map<String,Chapter> chapterMap=new HashMap<>(); Map<String,Chapter> chapterMap=new HashMap<>();
List<Chapter> roots=new ArrayList<>(); List<Chapter> roots=new ArrayList<>();
@ -167,13 +167,11 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
chapter.setChildren(new ArrayList<>()); chapter.setChildren(new ArrayList<>());
chapterMap.put(chapter.getId(),chapter); chapterMap.put(chapter.getId(),chapter);
} }
System.out.println(chapterMap);
for (Chapter chapter:chapters){ for (Chapter chapter:chapters){
String parentId=chapter.getPid(); String parentId=chapter.getPid();
if (parentId!=null){
if (!parentId.equals("0")){
Chapter parentChapter=chapterMap.get(parentId); Chapter parentChapter=chapterMap.get(parentId);
if (parentChapter != null) { if (parentChapter != null) {
parentChapter.getChildren().add(chapter); parentChapter.getChildren().add(chapter);
@ -183,7 +181,7 @@ public class ChapterServiceImpl extends ServiceImpl<ChapterMapper, Chapter> impl
roots.add(chapter); roots.add(chapter);
} }
} }
System.out.println(roots);
return roots; return roots;
} }

Loading…
Cancel
Save