多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
**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)); } ~~~