💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
**1.AccountMapper.java** ~~~ Account findById(int id); ~~~ **2.AccountMapper.xml** ~~~ <resultMap id="accountMap2" type="Account"> <id property="id" column="id"></id> <result property="money" column="money"></result> <!-- association: 表示要封装一个对象类型的属性 property: 属性名 javaType: 属性对应的Java类型 select: 访问该属性时,执行什么查询获得该属性 column: 执行select属性指定的查询时,使用哪一列的值作为参数 fetchType: 加载策略选择 --> <association property="user" javaType="User" select="com.nobb.mapper.UserMapper.findById" column="uid" fetchType="lazy"> </association> </resultMap> <select id="findById" resultMap="accountMap2"> select * from account where id = #{id} </select> ~~~ **3.UserMapper.java** ~~~ User findById(int id); ~~~ **4.UserMapper.xml** ~~~ <resultMap id="userMap11" type="User"> <id property="id" column="u_id"></id> <result property="name" column="u_name"></result> <result property="password" column="u_password"></result> </resultMap> <!--查询语句--> <select id="findById" resultMap="userMap11" parameterType="int"> select * from t_user where u_id = #{id} </select> ~~~ **5.测试语句** ~~~ @Test public void testFindById1(){ AccountMapper mapper = session.getMapper(AccountMapper.class); System.out.println(mapper.findById(1)); } ~~~