Mybatis通过list拼接多条sql语句

通过查询表的金额原值 对原值范围进行查找如下图对原值金额拼接

mybatis 的sql语句:

<select id="selectOriginalValue" parameterType="list" resultMap="OriginalValueMap">
        select t.name , t.id from
        <foreach collection="list" item="item" index="index" separator="UNION" open="(" close=")">
            select #{index} name,count(id) id
            from wi_erp_stock
            <where>

                <if test="item.endOriginalValue != null">
                    <![CDATA[  and original_value < #{item.endOriginalValue}  ]]>
                </if>
                <if test="item.startOriginalValue != null">
                    <![CDATA[  and original_value >= #{item.startOriginalValue} ]]>
                </if>
                <![CDATA[ and state=20 ]]>
            </where>

        </foreach> t
    </select>

 

posted @ 2020-05-08 14:31  石头三  阅读(871)  评论(0编辑  收藏  举报