将List集合泛型为对象中按照相同的成员属性值进行分组(Map集合)
示例代码
实体类:
@Data
public class Student implements Serializable {
private Long id;
private String name;
private Integer age;
private String sex;
}
持久层:
public interface Student implements Serializable {
List<Student> findByStudent();
}
<select id="findByStudent" resultType>
select * from student
</select>
业务层:
@Service
public class StudentServiceImpl{
public void show(){
List<Student> findByStudent = student.findByStudent(sysids);
Map<String, List<Student>> groupBy = findByStudent.stream().collect(Collectors.groupingBy(Student::getName));
}
}
THE END
暂无评论内容