mybatis if test 不為空字符串或null的解決
mybatis if test 不為空字符串或null
<sql id="public_content"> <if test="productId != null and productId !=''" > and a.product_id = #{productId,jdbcType=VARCHAR} </if> <if test="productDefinId != null" > and a.product_defin_id = #{productDefinId,jdbcType=VARCHAR} </if> <if test="productUid != null and productUid !=''"> and a.product_uid = #{productUid,jdbcType=VARCHAR} </if> <if test="productKey != null" > and a.product_key = #{productKey,jdbcType=VARCHAR} </if> <if test="prouuctSecret != null" > and a.prouuct_secret = #{prouuctSecret,jdbcType=VARCHAR} </if> <if test="productPass != null" > and a.product_pass = #{productPass,jdbcType=VARCHAR} </if> <if test="productVisitPass != null" > and a.product_visit_pass = #{productVisitPass,jdbcType=VARCHAR} </if> <if test="createTime != null and createTime !=''" > and a.create_time = #{createTime,jdbcType=VARCHAR} </if> <if test="pageSize != null and pageNum !=null " > ORDER BY a.product_id DESC limit #{pageNum},#{pageSize} </if> </sql>
mybatis中if test判斷數(shù)值字符串注意項(xiàng)
?? ?<if test="cutList != null"> ?? ? ? ?<if test="isInterrupt == '1'.toString() "> ?? ??? ?AND A.basic_id IN ( ?? ??? ? <foreach collection="cutList" item="item" index="index" separator="," > ? ? ? ? ? ? ??? ??? ?#{item} ? ? ? ? ? ?? ?</foreach> ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? </if> ? ? ? ? ? ? <if test="isInterrupt == '0'.toString() "> ?? ??? ?AND A.basic_id NOT IN ( ?? ??? ?<foreach collection="cutList" item="item" index="index" separator="," > ? ? ? ? ? ? ??? ??? ?#{item} ? ? ? ? ? ?? ?</foreach> ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? </if> ?? ?</if> ? ? ? ? ? ? ? ? ? ? ?
1. Mybatis中 if test 判斷數(shù)值字符串注意項(xiàng)
if test 判斷是否為某一數(shù)值字符串時(shí)需在數(shù)值字符串后加上toString()方法
如:
<if test="isInterrupt == '1'.toString() ">
2. Mybatis中遍歷list入?yún)?/p>
此處還有個(gè)知識(shí)點(diǎn)是mybatis使用foreach標(biāo)簽來(lái)遍歷入?yún)ist。
如:
?? ?<if test="isInterrupt == '1'.toString() "> ?? ??? ?AND A.basic_id IN ( ?? ??? ?<foreach collection="cutList" item="item" index="index" separator="," > ? ? ? ? ? ? ??? ? ? ?#{item} ? ? ? ? ? ?? ?</foreach> ? ? ? ? ? ? ? ? ) ? ? ? ? ? ? </if>
collection為需遍歷數(shù)組,item為當(dāng)前循環(huán)的變量,index為計(jì)數(shù)器,separator=","指循環(huán)一次則以“,”分隔
這里IN 的()可以直接用open="(" close=")"屬性設(shè)置
<foreach collection="cutList" item="item" index="index" open="(" close=")" separator="," >
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
java開(kāi)發(fā)WMS倉(cāng)庫(kù)商品預(yù)警需求示例解析
這篇文章主要為大家介紹了java開(kāi)發(fā)WMS倉(cāng)庫(kù)商品預(yù)警需求示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-04-04java http token請(qǐng)求代碼實(shí)例
這篇文章主要介紹了java http token請(qǐng)求,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03JVM的垃圾回收機(jī)制詳解和調(diào)優(yōu)
JVM的垃圾回收機(jī)制詳解和調(diào)優(yōu)...2006-12-12Java并發(fā)編程之JUC并發(fā)核心AQS同步隊(duì)列原理剖析
AbstractQueuedSynchronizer 簡(jiǎn)稱 AQS,可能我們幾乎不會(huì)直接去使用它,但它卻是 JUC 的核心基礎(chǔ)組件,支撐著 java 鎖和同步器的實(shí)現(xiàn),大神 Doug Lea 在設(shè)計(jì) JUC 包時(shí)希望能夠抽象一個(gè)基礎(chǔ)且通用的組件以支撐上層模塊的實(shí)現(xiàn),AQS 應(yīng)運(yùn)而生2021-09-09javaSE,javaEE,javaME的區(qū)別小結(jié)
本篇文章小編就為大家簡(jiǎn)單說(shuō)說(shuō)JavaSE、JavaEE、JavaME三者之間的區(qū)別,需要的朋友可以過(guò)來(lái)參考下,感興趣的小伙伴們可以參考一下2023-08-08Mybatis批量插入返回成功的數(shù)目實(shí)例
這篇文章主要介紹了Mybatis批量插入返回成功的數(shù)目實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-12-12基于Java實(shí)現(xiàn)Redis多級(jí)緩存方案
這篇文章主要介紹了Redis多級(jí)緩存方案分享,傳統(tǒng)緩存方案、多級(jí)緩存方案、JVM本地緩存,舉例說(shuō)明這些方案,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-03-03