Mybatis的xml查询sql拼接

字符串模糊查询 

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

日期时间范围查询 

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

集合范围查询 

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

布尔类型查询

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

猜你喜欢

转载自blog.csdn.net/Anenan/article/details/113845911