@Data
public class OneSubject {
private String id;
private String title;
private List<TwoSubject> children = new ArrayList<>();
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
Secondary entity class
@Data
public class TwoSubject {
private String id;
private String title;
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
3、controller
@GetMapping("getAllSubject")
public R getAllSubject(){
List<OneSubject> list = subjectService.getAllOneTwoSubject();
return R.Ok().data("list",list);
}
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
4、service
// Course classification list ( Tree form )
@Override
public List<OneSubject> getAllOneTwoSubject() {
//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 2 Class classification
QueryWrapper<EduSubject> wrapperTwo = new QueryWrapper<>();
wrapperTwo.ne("parent_id","0");
List<EduSubject> twoSubjectList = baseMapper.selectList(wrapperTwo);
// establish list aggregate , Used to store the final encapsulated data
List<OneSubject> finalSubjectList = new ArrayList<>();
//3、 Package level 1 Classification
for (int i = 0; i < oneSubjectList.size(); i++) {
EduSubject eduSubject = oneSubjectList.get(i);
OneSubject oneSubject = new OneSubject();
BeanUtils.copyProperties(eduSubject,oneSubject);
// Loop through and query all the secondary classifications in the primary classification
// establish list The set encapsulates the secondary classification of each primary classification
List<TwoSubject> twoFinalSubjectList = new ArrayList<>();
for (int j = 0; j < twoSubjectList.size(); j++) {
EduSubject tSubject = twoSubjectList.get(j);
if(tSubject.getParentId().equals(oneSubject.getId())){
TwoSubject twoSubject = new TwoSubject();
BeanUtils.copyProperties(tSubject,twoSubject);
twoFinalSubjectList.add(twoSubject);
}
}
// Put all the secondary classifications below the first level into the first level
oneSubject.setChildren(twoFinalSubjectList);
finalSubjectList.add(oneSubject);
}
//4、 Packaging secondary classification
return finalSubjectList;
}
<template><divclass="app-container"><el-inputv-model="filterText"placeholder="Filter keyword"style="margin-bottom:30px;"/><el-treeref="tree2":data="data2":props="defaultProps":filter-node-method="filterNode"class="filter-tree"default-expand-all/></div></template><script>
import subject from '@/api/edu/subject'
export default {
data() {
return {
filterText: '',
data2: [], // Return all classified data
defaultProps: {
# summary
On the whole , If you want to change your career to work as a programmer ,Java Development must be your first choice . But no matter what programming language you choose , Improving your hardware strength is the only way to get a high salary .
If you follow this learning route , You will have a more systematic knowledge network , It's not like learning knowledge in a scattered way . Personally, I don't recommend watching... At the beginning 《Java Programming idea 》、《Java The core technology 》 These books , After reading it, you will definitely give up studying . It is suggested that you can watch some videos to learn , It's very rewarding to buy these books when you can get started .
These videos, if needed , I can share it with you free of charge ,** Click here to get it for free **
