一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專(zhuān)注于服務(wù)器技術(shù)及軟件下載分享
分類(lèi)導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|VB|R語(yǔ)言|JavaScript|易語(yǔ)言|vb.net|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - Mybatis 中 Oracle 的拼接模糊查詢及用法詳解

Mybatis 中 Oracle 的拼接模糊查詢及用法詳解

2021-05-24 13:38飯娛咖啡 Java教程

這篇文章主要介紹了Mybatis 中 Oracle 的拼接模糊查詢及用法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

一、結(jié)論

這里先給大家看一下結(jié)論

oracle 中,拼接模糊查詢的正確寫(xiě)法

?
1
2
3
4
5
6
select a.user_id,
     a.user_name
   from user a
     and a.user_name like concat(concat('%','w'),'%')
     或者
     and a.user_name like '%' || 'w' || '%'

mybatis 中,拼接模糊查詢的正確寫(xiě)法

?
1
2
3
4
5
6
7
8
9
10
11
12
<select id="selectbyname" resultmap="baseresultmap">
   select a.user_id,
     a.user_name
   from t_base_user_info a
     <if test="username != null">
       and a.user_name like '%' || #{username} || '%'
     </if>
     或者
     <if test="username != null">
       and a.user_name like concat(concat('%','${username}'),'%')
     </if>
 </select>

注意 mybatis 中,拼接模糊查詢的用法

,是將傳入的值當(dāng)做字符串的形式。所以拼接的時(shí)候 #{username} 默認(rèn)自帶引號(hào)。例如: ${username} 直接轉(zhuǎn)為 ‘zhen'。

,是將傳入的數(shù)據(jù)直接顯示生成sql語(yǔ)句。所以拼接的時(shí)候
,是將傳入的數(shù)據(jù)直接顯示生成sql語(yǔ)句。所以拼接的時(shí)候
{username} 沒(méi)有默認(rèn)引號(hào)。例如:${username} 直接轉(zhuǎn)為 zhen 。

二、技巧:

剛開(kāi)始寫(xiě)的時(shí)候一直報(bào)錯(cuò),報(bào)錯(cuò)信息是這樣的:

    "message": "request processing failed; nested exception is org.mybatis.spring.mybatissystemexception: nested exception is org.apache.ibatis.type.typeexception: could not set parameters for mapping: parametermapping{property='username', mode=in, javatype=class java.lang.string, jdbctype=null, numericscale=null, resultmapid='null', jdbctypename='null', expression='null'}. cause: org.apache.ibatis.type.typeexception: error setting non null for parameter #1 with jdbctype null . try setting a different jdbctype for this parameter or a different configuration property. cause: java.sql.sqlexception: 無(wú)效的列索引",

我的寫(xiě)法是這樣的:           

?
1
2
3
4
5
6
7
8
9
10
11
12
<if test="_parameter != null">
--         and a.user_name like concat('%','#{username}','%')
          and a.user_name = #{username}
        </if>
<!--        <if test="usertype != null">
          and a.user_type = #{usertype}
        </if>
        <if test="mobilephoneno != null">
          and a.mobile_phone_no like concat('%','#{mobilephoneno}','%')
        </if>
        <if test="roleid != null">
          and b.role_id = #{roleid}<br>                </if>-->

后來(lái)我徹底凌亂了,于是就從頭開(kāi)始寫(xiě),結(jié)果就好了。

小結(jié):

出現(xiàn)的報(bào)錯(cuò)可能跟我之前寫(xiě)了太多的if 判斷語(yǔ)句有關(guān),于是先寫(xiě)一個(gè)簡(jiǎn)單的          

?
1
2
3
<if test="username != null">
       and a.user_name like '%' || #{username} || '%'
     </if>

這個(gè)可以執(zhí)行,其他再有什么條件加進(jìn)來(lái),稍微修改之后,都可以正常運(yùn)行。          

?
1
2
3
4
5
6
7
8
9
10
11
12
<if test="username != null">
       and a.user_name like concat(concat('%','${username}'),'%')
     </if>
     <if test="usertype != null">
       and a.user_type = #{usertype}
     </if>
     <if test="mobilephoneno != null">
       and a.mobile_phone_no like '%' || #{mobilephoneno} || '%'
     </if>
     <if test="baseroleinfo.roleid != null">
       and b.role_id = #{baseroleinfo.roleid}
     </if>

總結(jié)

以上所述是小編給大家介紹的mybatis 中 oracle 的拼接模糊查詢,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)服務(wù)器之家網(wǎng)站的支持!

原文鏈接:https://blog.csdn.net/ancdc/article/details/81479622

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 精品欧美一区二区三区久久久 | jk制服蕾丝超短裙流白浆 | 成年人视频免费在线播放 | 国产极品精频在线观看 | 国产农村乱子伦精品视频 | 边摸边吃奶玩乳尖视频 | 韩国久久 | 欧美视频一区二区三区在线观看 | 免费观看成年人视频 | 亚洲成色WWW久久网站夜月 | 美国69xxxx59 | 国产精品怡红院在线观看 | 天堂avav| 免费特黄一区二区三区视频一 | 欧美同性gayvidoes | 男人狂躁女人下面的视频免费 | 顶级欧美做受xxx000 | 日本在线播放视频 | 亚洲欧美国产精品久久久 | 天堂资源wwww在线看 | 日本中文字幕黑人借宿影片 | 久久偷拍国2017的 | 欧美三级不卡视频 | 欧美腐剧mm在线观看 | 桥本有菜在线四虎福利网 | 日本www色| 亚洲va久久久久 | 国产福利视频一区二区微拍 | 小早川怜子在线播放精品 | 欧美破处摘花 | 国产精品亚洲一区二区 | 日本无遮挡吸乳视频看看 | 国产高清国内精品福利 | 国产视频三区 | 69japanese日本100 6969精品视频在线观看 | 国产馆精品推荐在线观看 | 亚洲一卡2卡4卡5卡6卡残暴在线 | 日韩欧美在线看 | 男女操bb | 日本人泡妞18xxⅹ | 欧美黑人ⅹxxx片 |