合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
**1.UserMapper.java** ~~~ //查询所有账户及关联的角色 List<User> findAllWithRoles(); ~~~ **2.UserMapper.xml** ~~~ <resultMap id="userMapperWithRole" type="User"> <id property="id" column="u_id"></id> <result property="name" column="u_name"></result> <result property="password" column="u_password"></result> <collection property="roles" ofType="Role"> <id property="id" column="rid"></id> <result property="role_name" column="role_name"></result> <result property="role_desc" column="role_desc"></result> </collection> </resultMap> <select id="findAllWithRoles" resultMap="userMapperWithRole"> select * from t_user u left join user_role ur on u.u_id = ur.uid left join role r on ur.rid = r.id </select> ~~~ **3.测试代码** ~~~ @Test public void testFindAllWithRoles(){ UserMapper mapper = session.getMapper(UserMapper.class); System.out.println(mapper.findAllWithRoles()); } ~~~