mybatis传入字符串,集合,数组并遍历

mybatis传入字符串,集合,数组并遍历

<!--传递参数为字符串approveStatus =“通过,不通过” item为遍历后的参数-->
<if test="approveStatus != null and approveStatus!=''">
      and i.approve_status IN
        <foreach item="status" collection="approveStatus.split(',')" open="(" separator="," close=")">
            #{status}
        </foreach>
</if>
<!--传递参数为集合approveStatusList,集合中包含对象user ,approveStatusList={user1,user2 } -->
<if test="approveStatusList!= null and approveStatusList.size>0 ">
				AND operate_user in
				<foreach collection="approveStatusList" open="(" close=")" separator="," item="user" index="index">
					#{user.userName}
				</foreach>
			</if>
<!--传递参数为数组approveStatus =[通过,不通过] 此时collection必须为array item为传递的数组参数,且参数名要保持一致-->
<if test="approveStatus != null and approveStatus!=''">
      and i.approve_status IN
        <foreach item="approveStatus" collection="array" open="(" separator="," close=")">
            #{approveStatus}
        </foreach>
</if>

你可能感兴趣的:(java)