我有两个班级:
public class1{
private int id;
private List<Student> students;
}
public Student{
private name;
private address;
}
public Class2{
private int id;
private List<Person> person;
}
public Person{
private personName;
private location;
}
我必须将值从class1映射/复制到class2。我尝试使用dozer bean mapper API,但是我无法使用Person列表映射Student列表,因为它们具有不同的字段名称但功能相同。请帮助我进行推土机映射,或者如果有其他解决方案,请高度赞赏。
谢谢!
答案 0 :(得分:0)
尝试这样的事情:
public static List<Person> mapValues() {
List<Student> students = class1.getStudents(); // Assuming you have getters of students field
List<Person> persons = class2.getPersons(); // Assuming you have getters of persons field
for(Student student: students) {
Person person = new Person();
person.setPersonName(student.getName);
person.setLocation(student.getAddress);
persons.add(person);
}
return persons;
}