如何使用 Mybatis 将地址 class 映射到 EmployeeMap 中的地址列表?

How to map Addresses class with list of Address in EmployeeMap using Mybatis?

**如何使用 Mybatis 将地址 class 映射到 EmployeeMap 中的地址列表?我下面的代码正确吗? **

下面的查询是获取 employeeId 和 hos 多个地址位置。如何在 MyBatis 中映射这些字段?感谢您帮助绘制字段。仅供参考,我无法 post 使用其他字段

完成地址 class
<resultMap id="EmployeeMap" type="Employee">
    <result column="emplId" property="emplId"/>
    <collection property="addressList" >
        <result column="addressLineOne" property="addressLineOne"/>
        <result column="addressLineTwo" property="addressLineTwo"/>
        <result column="city" property="city"/>
        <result column="country" property="country"/>
        <result column="zipCode" property="zipCode"/>
    </collection>
 </resultMap>
 <select id="employeeData" resultMap="EmployeeMap">Select * from employee</select>

这是我的 Java 代码

public class Employee{

    String emplId;
    Addresses addressList;

    public String getEmplId() {
        return emplId;
    }

   public void setEmplId(Addresses value) {
        this.emplId = value;
   }


   public Addresses getAddressList() {
       return addressList;
   }

   public void setAddressList(Addresses value) {
       this.addressList = value;
   }
}
public class Addresses{

   List<Address> addresses;

   public List<Address> getAddresses() {
     if (addresses == null) {
        addresses = new ArrayList<Address>();
      }
     return this.addresses;
   }
 }
 public class Address{
   String city;

  public String getCity(){
       return city;
   }

   public void setCity(String value) {
       this.city = value;
   }
}

<collection />的目标属性是addressList.addresses,所以结果图应该是这样的:

<resultMap id="EmployeeMap" type="Employee">
  <id column="emplId" property="emplId"/>
  <collection property="addressList.addresses"
      javaType="list" ofType="Address">
    <result column="addressLineOne" property="addressLineOne"/>
    <result column="addressLineTwo" property="addressLineTwo"/>
    <result column="city" property="city"/>
    <result column="country" property="country"/>
    <result column="zipCode" property="zipCode"/>
  </collection>
</resultMap>

注意:您应该在父结果映射中指定<id />