先主查询,再关联子查询,不影响分页效果,否则子查询也会参与分页。
<resultMap id="Hdr" type="com.Hdr">
<id column="crh_id" property="id" JavaType="int"/>
<collection property="DtlList"
select="queryAllRmdDetail"
column="crh_id"
fetchType="eager">
</collection>
</resultMap>
<resultMap id="Dtl" type="com.Dtl">
</resultMap>
主查询:
<select id="queryByCondition" parameterTypjse="String" resultMap="Hdr"> </select>
在主查询后,通过传入主键id进行关联子查询:
<select id="queryAllDetail" parameterType="int" resultMap="Dtl">
SELECT * FROM biz_dtl WHERE crh_id = #{id}
</select>
主查询的结果是List,以及每一条记录的内涵List,性能是N+1次查询。
如果提高查询性能,可以使用别名的方式,在SQL中把子查询进行重新命名。
不过如果主查询包括SUM和Group语句,这种方式就不可以。
只有在平铺所有主从表的js时候可用。
<resultMap id="blogResult" type="Blog">
<id property="id" column="bljsog_id" />
<result property="title" column="blog_title"/>
www.devze.com<collection property="posts"
ofType="Post"
resultMap="blogPostResult"
columnPrefix="post_"/>
</resultMap>
<resultMap id="blogPostResult" type="Post">
<id property="id" column="id"/>
<result property="subject" column="subject"/>
<result property="body" column="body"/>
</resultMapphp>
到此这篇关于MyBATis分页查询主从表的实现示例的文章就介绍到这了,更多相关Mybatis分页查询主从表内容请搜索编程客栈(www.devze.com)以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程客栈(www.devze.com)!
加载中,请稍侯......
精彩评论