1、mybatis中嵌套查询参数传递问题记录
话不多说,直接上举例代码,好记性不如烂笔头
1.1 resultMap写法:
<resultMap id="deptMap" type="com.zx.test.vo.DataShareAppTypeSourceVo"> <id column="application_id" property="applicationId"></id> <result column="source_group" property="sourceGroup"></result> <result column="source_group_name" property="sourceGroupName"></result> <collection column="sourceGroup=source_group,appId=application_id" property="appTypeSourceList" select="getDataShareAppTypeSourceGroupSon" ofType="com.zx.test.domain.DataShareAppTypeSource"> </collection> </resultMap>
其中collection为子查询部分。
column代表需要传入的参数,多个参数如上述举例,使用逗号隔开。
property代码对应DataShareAppTypeSourceVo实体类中的子集的字段。
ofType代表子查询对应的实体类。
select代表当前子查询对应的方法。
1.2 父查询sql
<select id="getDataShareAppTypeSourceGroup" resultMap="deptMap"> select application_id ,source_group ,source_group_name from data_share_app_type_source where application_id = #{appId} group by source_group </select>
1.3 子查询sql
<select id="getDataShareAppTypeSourceGroupSon" resultType="com.zx.test.domain.DataShareAppTypeSource"> select application_id,source_group,source_group_name,id,name,comment,source,type from data_share_app_type_source where application_id = #{appId} and source_group = #{sourceGroup} </select>