Mybatis動(dòng)態(tài)sql----if--where

當(dāng)使用Map做為參數(shù)和pojo作參數(shù)時(shí),兩者配置文件寫(xiě)法相同


     <select id="SelectifwhereTestMap" parameterType="map" resultType="user">
    select * from user
    <where>
    <if test="username!=null and username!=''">
    and username like '%${username}%' 
    </if>
    
    <if test="sex!=null and sex!=''">
    and sex=#{sex} 
    </if>
    
    <if test="address!=null and address!=''">
    and address like '%${address}%' 
    </if>
    </where><!--where可以去除第一個(gè)空格或者OR-->
    </select> 
    ```


<select id="SelectifwhereTestUser" parameterType="user" resultType="user">
select * from user
<where><!--where可以去除第一個(gè)空格或者OR-->
<if test="username!=null and username!=''">
and username like '%${username}%' 
</if>

<if test="sex!=null and sex!=''">
and sex=#{sex} 
</if>

<if test="address!=null and address!=''">
and address like '%${address}%' 
</if>
</where>
</select>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Mybatis框架會(huì)根據(jù) 傳入的參數(shù)判斷有沒(méi)有值,如果有值則 會(huì)加上where 并且去掉第一個(gè)and
    資深菜雞程序員閱讀 172評(píng)論 0 0
  • 1. 簡(jiǎn)介 1.1 什么是 MyBatis ? MyBatis 是支持定制化 SQL、存儲(chǔ)過(guò)程以及高級(jí)映射的優(yōu)秀的...
    笨鳥(niǎo)慢飛閱讀 6,248評(píng)論 0 4
  • 阿里巴巴 JAVA 開(kāi)發(fā)手冊(cè) 1 / 32 Java 開(kāi)發(fā)手冊(cè) 版本號(hào) 制定團(tuán)隊(duì) 更新日期 備 注 1.0.0 阿...
    糖寶_閱讀 7,886評(píng)論 0 5
  • feisky云計(jì)算、虛擬化與Linux技術(shù)筆記posts - 1014, comments - 298, trac...
    不排版閱讀 4,354評(píng)論 0 5
  • 第1章 課程準(zhǔn)備 本章首先從課程重點(diǎn)、特點(diǎn)、適合人群及學(xué)習(xí)收獲幾個(gè)方面對(duì)課程進(jìn)行整體的介紹,然后會(huì)從一個(gè)實(shí)際的計(jì)數(shù)...
    cuzz_閱讀 777評(píng)論 0 13

友情鏈接更多精彩內(nèi)容