zoukankan      html  css  js  c++  java
  • mybatis xml trim choose when 用法

    最近遇到一个问题,需要sql 类似:

    select * where  xx = 'xx'  and ( xx='xx' or xx='xx') order by id asc

    使用方法1:

      可以去掉 前面 ” and (“     和后面的 ”)“

    <trim prefix="AND(" suffix=")" prefixoverride="AND|OR">
        <if test="name != null and name.length()>0"> AND name=#{name}</if>
        <if test="gender != null and gender.length()>0"> AND gender=#{gender}</if>
    </trim>
    
    
    
    <trim prefix="AND(" suffix=")" prefixoverride="AND|OR"> 

    使用方法2:

    SELECT cb_p FROM xxx WHERE  app_source = #{appsource}  AND channel = #{channel} AND model = #{model} AND (
    
            <choose>
                <when test=" (imei != null and imei != '' ) or (androidid != null and androidid != '') or (idfa != null and idfa != '' )  or (oaid != null and oaid != '') or (mac != null and mac != '')">
                    <trim prefix="" prefixOverrides ="OR"  >
                        <if test="imei != null and imei != ''">
                            OR  imei = #{imei}
                        </if>
                        <if test="androidid != null and androidid != ''  ">
                            OR  android_id = #{androidid}
                        </if>
                        <if test="idfa != null and idfa != '' ">
                            OR  idfa = #{idfa}
                        </if>
                        <if test="oaid != null and oaid != '' ">
                            OR  oaid = #{oaid}
                        </if>
                        <if test="mac != null and mac != '' ">
                            OR  mac = #{mac}
                        </if>
    
                    </trim>
    
                </when>
                <otherwise>
                     uip = #{ip} and  uua = #{uua}
                </otherwise>
    
            </choose>
    
                ) ORDER BY ts  DESC LIMIT 1

      

  • 相关阅读:
    Linux7运维视频教程
    大型C++网络游戏开发视频教程
    Hadoop实战视频教程下载
    Greenplum分布式数据库开发入门到精通
    Greenplum Hadoop视频教程_Hadoop应用案例剖析
    Linux7企业级运维高端培训视频教程
    咯咯咯
    第五周作业
    数组
    2019年春季学期第三周作业
  • 原文地址:https://www.cnblogs.com/chen-msg/p/15412145.html
Copyright © 2011-2022 走看看