像这种数据,现在想转成树结构返回给前端。分为123级,每一级都去重
这个问题其实很简单,不废话,直接上代码……
//此处我为了方便,数据库创建了表,查询表得到数据
List<Student> studentList = this.list();
if(!CollectionUtils.isEmpty(studentList)){
//使用JDK1.8新特性对数据进行多级分组
Map<String,Map<String,List<Student>>> map = studentList.stream().collect(Collectors.groupingBy(Student::getName,Collectors.groupingBy(Student::getSubject)));
}