企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**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()); } ~~~