mybatis Mapper resultMap Collection 连接查询

场景:查详情接口,连接查询。 查询投票详情同时连接查询投票选项

问题:参数传递 column=“openId=open_id,voteId=vote_id}”

知识点

  1. resultMap .
// 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>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值