当前位置:网站首页>Course classification tree structure display

Course classification tree structure display

2022-06-11 03:37:00 The bright moon is always fresh

The course classification tree structure displays

1、 Analyze requirements

 Insert picture description here
Refer to the existing modules for implementation

2、 Copy page elements

Reference has been made to tree page

3、 Page data structure

 Insert picture description here

4、 Implementation interface 
(1) establish vo
@Data
public class OneSubjectVo {
    

    @ApiModelProperty(value = " Course category ID")
    private String id;

    @ApiModelProperty(value = " Category name ")
    private String title;
    
    private List<TwoSubjectVo> children =new ArrayList<>();

}
@Data
public class TwoSubjectVo {
    
    @ApiModelProperty(value = " Course category ID")
    private String id;

    @ApiModelProperty(value = " Category name ")
    private String title;

}

    @ApiOperation(value = " Query all course classifications ")
    @GetMapping("getAllSubject")
    public R getAllSubject(){
    
        List<OneSubjectVo> allSubjectList  = subjectService.getAllSubject();
        return R.ok().data("allSubject",allSubjectList);
    }
// Query all course classifications 
    @Override
    public List<OneSubjectVo> getAllSubject() {
    
        //1 Query all first level classifications 
        QueryWrapper<EduSubject> wrapperOne = new QueryWrapper<>();
        wrapperOne.eq("parent_id","0");
        List<EduSubject> oneSubjectList = baseMapper.selectList(wrapperOne);
        //2 Query all secondary classifications 
        QueryWrapper<EduSubject> wrapperTwo = new QueryWrapper<>();
        // It's not equal to 
        wrapperTwo.ne("parent_id","0");
        List<EduSubject> twoSubjectList = baseMapper.selectList(wrapperTwo);

        //3 Package level 1 Classification 
        List<OneSubjectVo> allSubjectList = new ArrayList<>();
        for (int i = 0; i <oneSubjectList.size() ; i++) {
    
            //3.1 Take out each primary classification 
            EduSubject oneSubject = oneSubjectList.get(i);
            //3.2EduSubject conversion OneSubjectVo
            OneSubjectVo oneSubjectVo  = new OneSubjectVo();
// oneSubjectVo.setId(oneSubject.getId());
// oneSubjectVo.setTitle(oneSubject.getTitle());
            // No problem with fewer fields   Too much is not enough 
            BeanUtils.copyProperties(oneSubject,oneSubjectVo);
            allSubjectList.add(oneSubjectVo);
            //4 Find the second level related to the root level and encapsulate it 
            List<TwoSubjectVo> twoSubjectVos  = new ArrayList<>();
            for (int m = 0; m < twoSubjectList.size(); m++) {
    
                //4.1 Take out each secondary classification 
                EduSubject twoSubject = twoSubjectList.get(m);
                //4.2  Determine whether it belongs to this level 
                if(twoSubject.getParentId().equals(oneSubject.getId())){
    
                    //4.3EduSubject conversion TwoSubjectVo
                    TwoSubjectVo twoSubjectVo = new TwoSubjectVo();
                    BeanUtils.copyProperties(twoSubject,twoSubjectVo);
                    twoSubjectVos.add(twoSubjectVo);
                }
            }
            oneSubjectVo.setChildren(twoSubjectVos);
        }

        return allSubjectList;
    }

原网站

版权声明
本文为[The bright moon is always fresh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203020554362651.html