💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**1.UserMapper.java** ~~~ //查询用户和用户关联的账号信息 List<User> findAllWithAccount(); ~~~ **2.UserMapper.xml** ~~~ <resultMap id="userMapperWithAccount" 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:集合属性名 ofType:集合中封装的对象类型 --> <collection property="accounts" ofType="Account"> <id property="id" column="aid"></id> <result property="money" column="money"></result> </collection> </resultMap> <select id="findAllWithAccount" resultMap="userMapperWithAccount"> select *,a.id 'aid' from t_user u left join account a on u.u_id = a.uid </select> ~~~ **3.测试语句** ~~~ @Test public void testFindAllWithAccount(){ UserMapper mapper = session.getMapper(UserMapper.class); System.out.println(mapper.findAllWithAccount()); } ~~~