MyBaits集合的嵌套 Select 查询

Posted flying-boy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyBaits集合的嵌套 Select 查询相关的知识,希望对你有一定的参考价值。

---恢复内容开始---

<resultMap id="slist" type="com.qujiali.model.AdShareInfo">
<id column="id_" property="id" />
<result column="type_" property="type" />
<result column="title_" property="title" />
<result column="content_" property="content" />
<result column="requirement_" property="requirement" />
<result column="link_url" property="linkUrl" />
<result column="reward_amount" property="rewardAmount" />
<result column="share_company" property="shareCompany" />
<result column="share_mode" property="shareMode" />
<result column="share_number" property="shareNumber" />
<result column="userShareEnable" property="userShareEnable" />
<result column="company_abbreviation" property="companyAbbreviation" />
<collection property="adImageContentList"
ofType="com.qujiali.model.AdShareImage" column="id_" select="adImageContentSel">
</collection>
<collection property="adImageRequireList"
ofType="com.qujiali.model.AdShareImage" column="id_" select="adImageRequireSel">
</collection>
</resultMap>
<resultMap type="com.qujiali.model.AdShareImage" id="adImageContentMap">
<result column="picture_url" property="pictureUrl" />
</resultMap>
<select id="findById" resultMap="slist"
parameterType="java.lang.Long">
select
g.*,
c.share_number,
ac.company_abbreviation
from
ad_share_info g
LEFT JOIN ad_company ac
ON g.share_company = ac.id_
LEFT JOIN ad_share_statistics c
ON g.id_ = c.share_id
WHERE g.id_ = #{id}
</select>
<select id="adImageContentSel" resultMap="adImageContentMap" parameterType="java.lang.Long">
select
f.picture_url
from ad_share_image f
where f.picture_type = ‘1‘
and f.ad_share_id = #{id}
</select>
<select id="adImageRequireSel" resultMap="adImageContentMap" parameterType="java.lang.Long">
select
f.picture_url
from ad_share_image f
where f.picture_type = ‘2‘
and f.ad_share_id = #{id}
</select>

---恢复内容结束---

以上是关于MyBaits集合的嵌套 Select 查询的主要内容,如果未能解决你的问题,请参考以下文章

Mybatis resultMap 嵌套集合

mybaits自连接查询

mysql_数据查询_嵌套查询

Mybaits 快速入门代码实例(maven代码版)

mybaits-plus lambdaQuery() 和 lambdaUpdate() 比较常见的使用方法

mybaits-plus lambdaQuery() 和 lambdaUpdate() 比较常见的使用方法