mybatis的foreach标签的用法

来源:互联网 发布:青岛seo搜索排名优化 编辑:程序博客网 时间:2024/05/18 04:55

本人是新人,如果各位大神觉得代码需要修改的地方,请留下你宝贵的建议.在公司处理一个需要多条件查询的业务,但是公司不让循环查询,然后在网上搜了一下发现在mybatis循环用foreach标签,但是这个标签一般用于配合in用的,然后我想了想是不是可以循环集合,试了一下真行。但是就是查询速度有点下降,如果有人能优化一下,请告诉我一声.

<select id="selectListByCustomerStatus" parameterType="java.util.Map" resultMap="resultCount">

        select customer_id
        ,count(1) customer_count
        from tb_customer_status
        <where>
            <if test="assignHistoryDOs != null">
                <foreach item="item" index="index" collection="assignHistoryDOs" open="(" separator="or" close=")">
                    customer_id=#{item.customerId} and add_time  &gt; #{item.addTime}
                </foreach>
            </if>
            <if test="employeeId != null">
                and  consultant = #{employeeId}
            </if>
        </where>
        group by customer_id
</select>




原创粉丝点击