这里是同时也是学校老师的博士生。这两个对象之间的共同点是它们的名称。所以我用他们的名字过滤数据。直到我在下面的 MyMain 类中编写的代码,我能够过滤公共记录并获取学生数据。但我也想要学生和教师的详细信息,并在 StudentTeacherMapper 中设置。请帮我在 StudentTeacherMapper 类中设置字段。谢谢你。
@Getter
@Setter
public class PHDStudent {
private int studentId;
private String studentName;
private String grade;
private int rank;
}
@Getter
@Setter
public class SCHLTeacher {
private int teacherId;
private String teacherName;
private String place;
private Long Salary;
}
@Getter
@Setter
public class StudentTeacherMapper {
private int teacherId;
private String teacherName;
private String place;
private Long Salary;
private int studentId;
private String studentName;
private String grade;
private int rank;
}
public class MyMain {
public static void main(String[] args) {
List<SCHLTeacher> teachList = new ArrayList<>();
List<PHDStudent> studList = new ArrayList<>();
mapStudentTeacherData(teachList, studList);
List<PHDStudent> studentList = teachList.stream().flatMap(
teach -> studList.stream().filter(predicate -> predicate.getStudentName().equals(teach.getTeacherName())))
.collect(Collectors.toList());
StudentTeacherMapper mapper = new StudentTeacherMapper();
//set data in mapper
}
private static void mapStudentTeacherData(List<SCHLTeacher> teachList, List<PHDStudent> studList) {
SCHLTeacher teach1 = new SCHLTeacher();
teach1.setPlace("Mumbai");
teach1.setSalary(100000L);
teach1.setTeacherId(11);
teach1.setTeacherName("Ms.Grace444");
SCHLTeacher teach2 = new SCHLTeacher();
teach2.setPlace("Delhi");
teach2.setSalary(160000L);
teach2.setTeacherId(22);
teach2.setTeacherName("Mr.Paul123");
teachList.add(teach1);
teachList.add(teach2);
PHDStudent stud1 = new PHDStudent();
stud1.setGrade("A");
stud1.setRank(1);
stud1.setStudentId(11);
stud1.setStudentName("Ms.Grace444");
PHDStudent stud2 = new PHDStudent();
stud2.setGrade("C");
stud2.setRank(44);
stud2.setStudentId(22);
stud2.setStudentName("Mr.Paul123");
PHDStudent stud3 = new PHDStudent();
stud3.setGrade("B");
stud3.setRank(12);
stud3.setStudentId(45);
stud3.setStudentName("Mr.X22");
studList.add(stud1);
studList.add(stud2);
studList.add(stud3);
}
}