延迟加载

一对一

<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 @   max_yan  阅读(11)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
点击右上角即可分享
微信分享提示