我有Departments
的列表,而列表又依次有Employee
的列表,如下所示:
Employee emp1 = new Employee("100", "xyz");
Employee emp2 = new Employee("200", "pqr");
Department dept1 = new Department("10", "Account");
List<Employee> empList = new ArrayList<Employee>();
empList.add(emp1);
empList.add(emp2);
dept1.setEmpList(empList);
下面是Department
和Employee
类:
public class Employee {
private String id;
private String name;
}
public class Department {
private String id;
private String name;
List<Employee> empList;
}
我想要一个Employee
列表,其中包含部门ID和名称
public class EmployeeD {
private String id;
private String name;
private String deptId;
private String deptName;
}
public class EmployeeDepartmentDTO {
private List<EmployeeD> empList;
}
我尝试过的操作如下:
<mapping map-id="depEmpD">
<class-a>streammapper.Department</class-a>
<class-b>streammapper.EmployeeD</class-b>
<field>
<a>id</a>
<b>deptId</b>
</field>
<field>
<a>name</a>
<b>deptName</b>
</field>
</mapping>
<mapping map-id="department">
<class-a>streammapper.Department</class-a>
<class-b>streammapper.EmployeeDepartmentDTO</class-b>
<field map-id="depEmpD">
<a>empList</a>
<b>empList</b>
</field>
</mapping>
通过以下映射,我可以在没有EmployeeD
和deptId
的情况下成功创建deptName
列表:
<mapping map-id="depEmpD">
<class-a>streammapper.Department</class-a>
<class-b>streammapper.EmployeeD</class-b>
<field>
<a>id</a>
<b>deptId</b>
</field>
<field>
<a>name</a>
<b>deptName</b>
</field>
</mapping>
<mapping map-id="department">
<class-a>streammapper.Department</class-a>
<class-b>streammapper.EmployeeDepartmentDTO</class-b>
<field>
<a>empList</a>
<b>empList</b>
</field>
</mapping>
我需要一个EmployeeD
列表,该列表还将在deptId
对象中包含deptName
和EmployeeDepartmentDTO
。