mybatis 動態sql 查詢列表時添加條件判斷!

條件查詢 

 /*條件查詢*/
    <if test="nZbyggh != null and nZbyggh != ''">
      and  o.nZbyggh = #{nZbyggh}
    </if>
    <if test="cSxbt != '' and cSxbt != null">
      <bind name="cSxbtLike" value="'%'+cSxbt+'%'"/>
      AND o.c_sxbt LIKE #{cSxbtLike}
    </if>
    <if test="dBlsx != null">
      and o.dBlsx = #{dDjrq}
    </if>

比較 

  • &gt;  -- geat than
  • &gte;
  • &lt; -- less than
  • &lte;

 

<if test='id != null and id gt 28'></if>

 

空判斷 

<if test="id != null and id !=''"></if>

 

條件判斷

    <if test="ndclzt != '' and ndclzt == 1">
      and n_clzt  in('0','2')
    </if>
    <if test="ndclzt != '' and ndclzt == 0">
      AND n_clzt ='0'
    </if>
    <if test="ndclzt != '' and ndclzt == 3">
      AND n_clzt in('1','3')
    </if>
    <if test="ndclzt != '' and ndclzt == 4">
      AND n_clzt ='4'
    </if>
<if test="username != null and username.indexOf('ji') == 0"> </if> <!-- 是否以什麼開頭 -->
<if test="username != null and username.lastIndexOf('ji') > 0"></if>  <!-- 是否以什麼結尾 -->

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章