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è)知識點(diǎn)是mybatis使用foreach標(biāo)簽來遍歷入?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)文章
JVM的垃圾回收機(jī)制詳解和調(diào)優(yōu)
JVM的垃圾回收機(jī)制詳解和調(diào)優(yōu)...2006-12-12
Java并發(fā)編程之JUC并發(fā)核心AQS同步隊(duì)列原理剖析
AbstractQueuedSynchronizer 簡稱 AQS,可能我們幾乎不會直接去使用它,但它卻是 JUC 的核心基礎(chǔ)組件,支撐著 java 鎖和同步器的實(shí)現(xiàn),大神 Doug Lea 在設(shè)計(jì) JUC 包時(shí)希望能夠抽象一個(gè)基礎(chǔ)且通用的組件以支撐上層模塊的實(shí)現(xiàn),AQS 應(yīng)運(yùn)而生2021-09-09
javaSE,javaEE,javaME的區(qū)別小結(jié)
本篇文章小編就為大家簡單說說JavaSE、JavaEE、JavaME三者之間的區(qū)別,需要的朋友可以過來參考下,感興趣的小伙伴們可以參考一下2023-08-08
Mybatis批量插入返回成功的數(shù)目實(shí)例
這篇文章主要介紹了Mybatis批量插入返回成功的數(shù)目實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-12-12
基于Java實(shí)現(xiàn)Redis多級緩存方案
這篇文章主要介紹了Redis多級緩存方案分享,傳統(tǒng)緩存方案、多級緩存方案、JVM本地緩存,舉例說明這些方案,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-03-03

