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>

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

猜你喜欢

转载自www.cnblogs.com/Flying-Boy/p/10773629.html