企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
**1.UserMapper.java** ~~~ //根据id查询用户及关联的所有账户信息 User findById1(int id); ~~~ **2.UserMapper.xml** ~~~ <resultMap id="findById1Map" 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="accounts" ofType="Account" select="com.nobb.mapper.AccountMapper.findByUid" column="u_id" fetchType="lazy"> </collection> </resultMap> <select id="findById1" resultMap="findById1Map"> select * from t_user where u_id = #{id} </select> ~~~ **3.AccountMapper.java** ~~~ //通过uid 查询 List<Account> findByUid(int uid); ~~~ **4.AccountMapper.xml** ~~~ <select id="findByUid" resultType="Account"> select * from account where uid = #{uid} </select> ~~~ **5.测试代码** ~~~ @Test public void testFindById1(){ UserMapper mapper = session.getMapper(UserMapper.class); System.out.println(mapper.findById1(15)); } ~~~