mybatis Mapper resultMap Collection 连接查询
场景:查详情接口,连接查询。 查询投票详情同时连接查询投票选项
问题:参数传递 column=“openId=open_id,voteId=vote_id}”
知识点
- resultMap .
<resultMap id="appDeliberativeVoteDetailsMap" type="com.sinoecare.vc2.common.core.bean.AppDeliberativeVoteDetails">
<id property="id" column="id"/>
<result property="voteId" column="vote_id"/>
<result property="optionId" column="option_id"/>
<result property="openId" column="open_id"/>
<result property="name" column="name"/>
<result property="phone" column="phone"/>
<result property="voteTime" column="vote_time"/>
<collection property="options" column="{openId=open_id,voteId=vote_id}" ofType="com.sinoecare.vc2.common.core.bean.AppDeliberativeVoteDetails"
select="queryOptions" javaType="java.util.List">
</collection>
</resultMap>
<select id="getAppDeliberativeVoteDetailsPage" resultMap="appDeliberativeVoteDetailsMap">
SELECT
t1.id,
t1.vote_id,
t1.option_id,
t1.open_id,
t1.name,
t1.phone,
t1.vote_time
FROM app_deliberative_vote_details t1
<where>
<if test="appDeliberativeVoteDetails.id != null and appDeliberativeVoteDetails.id.trim() != ''">
AND t1.id = #{appDeliberativeVoteDetails.id}
</if>
<if test="appDeliberativeVoteDetails.voteId != null and appDeliberativeVoteDetails.voteId.trim() != ''">
AND t1.vote_id = #{appDeliberativeVoteDetails.voteId}
</if>
<if test="appDeliberativeVoteDetails.optionId != null and appDeliberativeVoteDetails.optionId.trim() != ''">
AND t1.option_id = #{appDeliberativeVoteDetails.optionId}
</if>
<if test="appDeliberativeVoteDetails.openId != null and appDeliberativeVoteDetails.openId.trim() != ''">
AND t1.open_id = #{appDeliberativeVoteDetails.openId}
</if>
<if test="appDeliberativeVoteDetails.name != null and appDeliberativeVoteDetails.name.trim() != ''">
AND t1.name = #{appDeliberativeVoteDetails.name}
</if>
<if test="appDeliberativeVoteDetails.phone != null and appDeliberativeVoteDetails.phone.trim() != ''">
AND t1.phone = #{appDeliberativeVoteDetails.phone}
</if>
<if test="appDeliberativeVoteDetails.voteTime != null and appDeliberativeVoteDetails.voteTime.trim() != ''">
AND t1.vote_time = #{appDeliberativeVoteDetails.voteTime}
</if>
</where>
group by t1.open_id
order by t1.vote_time desc
</select>
<select id="queryOptions" resultType="com.sinoecare.vc2.common.core.bean.AppDeliberativeVoteDetails">
SELECT
t1.id,
t1.vote_id,
t1.option_id,
t1.open_id,
t2.option_name as optionName ,
t1.name,
t1.phone,
t1.vote_time
FROM app_deliberative_vote_details t1
left join app_deliberative_vote_options t2 on t1.option_id = t2.id
where t1.vote_id = #{voteId} and t1.open_id = #{openId}
</select>