mybaitis的延迟加载

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

mybaitis的延迟加载

赟麟   2020-02-17 我要评论

概念:延迟加载:用到的时候才加载

因为我们在多表查询是,效率不如单表快,多个单表查询,然后使用懒加载,完成

多表关联查询


什么情况下使用懒加载

mybaitis中的表关系是一对一或者一对多的时候

我们在一对多的时候,通常使用延迟加载啊,一对一的时候,使用立即加载。

我们在写sql时,如果使用多表关联查询,name跟延迟加载就没有关系了,我们要使用延迟加载,不能

使用多表关联查询


代码如下:

<resultMap id="parent" type="com.ssw.pojo.Setmeal">
<id column="id" property="id"/>
<result property="name" column="name"/>
<result column="code" property="code"/>
<result column="helpCode" property="helpCode"/>
<result column="sex" property="sex"/>
<result column="age" property="age"/>
<result column="price" property="price"/>
<result column="remark" property="remark"/>
<result column="attention" property="attention"/>
<result column="img" property="img"/>
</resultMap>
<resultMap id="setmeal" type="com.ssw.pojo.Setmeal" extends="parent">
<collection property="checkGroups"
ofType="com.ssw.pojo.CheckGroup"
select="com.ssw.dao.CheckGroupDao.findCheckGroup"
column="id"
></collection>
</resultMap>

<select id="findById" parameterType="int" resultMap="setmeal">
select * from t_setmeal where id=#{id}
</select>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们