public class User implements Serializable {
private Integer id;
private String username;
private Date birthday;
private String sex;
private String address;
**private List<Account> accounts** //在User中关联了Account信息
......
}
配置文件
<resultMap type="user" id="userMap">
<id column="id" property="id"></id>
<result column="username" property="username"/>
<result column="address" property="address"/>
<result column="sex" property="sex"/>
<result column="birthday" property="birthday"/>
<!-- collection 是用于建立一对多中集合属性的对应关系
ofType 用于指定集合元素的数据类型 -->
<collection property="accounts" ofType="account">
<id column="aid" property="id"/>
<result column="uid" property="uid"/>
<result column="money" property="money"/>
</collection>
</resultMap
collection 部分定义了用户关联的账户信息。表示关联查询结果集
property=“accList” :
关联查询的结果集存储在 User 对象的上哪个属性。
ofType=“account” :
指定关联查询的结果集中的对象类型即List中的对象类型。此处可以使用别名,也可以使用全限定名