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ù)值字符串注意項
?? ?<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ù)值字符串注意項
if test 判斷是否為某一數(shù)值字符串時需在數(shù)值字符串后加上toString()方法
如:
<if test="isInterrupt == '1'.toString() ">
2. Mybatis中遍歷list入?yún)?/p>
此處還有個知識點是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為計數(shù)器,separator=","指循環(huán)一次則以“,”分隔
這里IN 的()可以直接用open="(" close=")"屬性設(shè)置
<foreach collection="cutList" item="item" index="index" open="(" close=")" separator="," >總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
JVM的垃圾回收機(jī)制詳解和調(diào)優(yōu)
JVM的垃圾回收機(jī)制詳解和調(diào)優(yōu)...2006-12-12
Java并發(fā)編程之JUC并發(fā)核心AQS同步隊列原理剖析
AbstractQueuedSynchronizer 簡稱 AQS,可能我們幾乎不會直接去使用它,但它卻是 JUC 的核心基礎(chǔ)組件,支撐著 java 鎖和同步器的實現(xiàn),大神 Doug Lea 在設(shè)計 JUC 包時希望能夠抽象一個基礎(chǔ)且通用的組件以支撐上層模塊的實現(xiàn),AQS 應(yīng)運而生2021-09-09
javaSE,javaEE,javaME的區(qū)別小結(jié)
本篇文章小編就為大家簡單說說JavaSE、JavaEE、JavaME三者之間的區(qū)別,需要的朋友可以過來參考下,感興趣的小伙伴們可以參考一下2023-08-08

