Mybatis xml query sql splicing

String fuzzy query 

        <if test="userName != null and userName!= ''">
            AND `user_name` LIKE CONCAT(CONCAT('%', #{userName}), '%')
        </if>

Date and time range query 

        <if test="dto.metaCreatedStart != null">
            AND `meta_created` &gt;= #{dto.metaCreatedStart}
        </if>
        <if test="dto.metaCreatedEnd != null">
            AND `meta_created` &lt;= #{dto.metaCreatedEnd}
        </if>

Collection range query 

        <if test="frameIds != null and frameIds.size> 0">
            AND `frame_id ` IN (<foreach collection="frameIds" item="frameId" separator=","> #{frameId} </foreach>)
        </if>

Boolean query

        <if test="isNew != null and isNew == true">
                AND `type` &lt; 5
        </if>

 

Guess you like

Origin blog.csdn.net/Anenan/article/details/113845911