<mappernamespace="com.itheima.dao.IUserDao"><!-- 定义User的resultMap--><resultMapid="userMap"type="user"><idproperty="id"column="id"></id><resultproperty="username"column="username"></result><resultproperty="address"column="address"></result><resultproperty="sex"column="sex"></result><resultproperty="birthday"column="birthday"></result><!-- 配置角色集合的映射 --><collectionproperty="roles"ofType="role"><idproperty="roleId"column="rid"></id><resultproperty="roleName"column="role_name"></result><resultproperty="roleDesc"column="role_desc"></result></collection></resultMap><!-- 查询所有 --><selectid="findAll"resultMap="userMap">
select u.*,r.id as rid,r.role_name,r.role_desc from user u
left outer join user_role ur on u.id = ur.uid
left outer join role r on r.id = ur.rid
</select></mapper>