延迟加载

一对一

<resultMap type="account" id="accountMap">
      <id column="aid" property="id"/>
      <result column="uid" property="uid"/>
      <result column="money" property="money"/>
      <!-- 它是用于指定从表方的引用实体属性的 -->
      <association property="user" javaType="user"
          select="com.itheima.dao.IUserDao.findById"
          column="uid">
      </association>
</resultMap>

一对多

<resultMap type="user" id="userMap">
    <id column="id" property="id"></id>
    <result column="username" property="username"/>
    <result column="address" property="address"/>
    <result column="sex" property="sex"/>
    <result column="birthday" property="birthday"/>
    <!-- collection 是用于建立一对多中集合属性的对应关系
    ofType 用于指定集合元素的数据类型
    select 是用于指定查询账户的唯一标识(账户的 dao 全限定类名加上方法名称)
    column 是用于指定使用哪个字段的值作为条件查询
    -->
    <collection property="accounts" ofType="account"
        select="com.itheima.dao.IAccountDao.findByUid"
        column="id">
    </collection>
</resultMap>

开启延迟加载的支持
在SqlMapConfig.xml中配置

<settings>
    <setting name="lazyLoadingEnabled" value="true"/>
    <setting name="aggressiveLazyLoading" value="false"/>
</settings>
posted @ 2022-12-21 11:36  max_yan  阅读(20)  评论(0)    收藏  举报