mybatis xml中实现一对多查询时, 子查询带多个参数

1、mapper文件中:

List<Object> getXXXXX(@Param("taskId")String taskId,@Param("taskType")String taskType);

2、xml文件中

<select id="" resultMap="" >

     select tst.id subTaskId,......

      from ......

</select>

  <resultMap type="" id="">
          <id property="id" column=""/>
        <result property="" column=""/>
        .....

       <collection property="返回结果的key,对应实体内的字段" ofType="这里是查询返回的类型" 
            column="{subTaskId=subTaskId,taskType=taskType}" select="getVails"/>
  </resultMap>

  <select id="getVails" parameterType="java.util.Map" resultType="">
  	<choose>
  		<when test="taskType == '6'.toString">
  			SELECT .......
		    from ......
		    where 
			   xxxxx = #{subTaskId}
  		</when>
  		<otherwise>
  		    SELECT ......
		    from ......	
		    where 
			   xxxx = #{subTaskId}
  		</otherwise>
  	</choose>     	
 </select>

重点是   column="{subTaskId=subTaskId,taskType=taskType}"    这句

和   parameterType="java.util.Map"  这句

注意:在这里省略了很多不必要的东西,不必介意,只需要看重点就好,如果有什么问题,可留言,我回及时回答的

猜你喜欢

转载自blog.csdn.net/weixin_40841731/article/details/84233464
今日推荐