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)簽來遍歷入?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實(shí)現(xiàn)RSA加密與驗(yàn)證的方法詳解
RSA是一種非對(duì)稱加密算法,是目前廣泛應(yīng)用于加密和數(shù)字簽名領(lǐng)域的一種加密算法,本文主要講述如何通過Java實(shí)現(xiàn)RSA加密與驗(yàn)證,應(yīng)用場景為與其他平臺(tái)對(duì)接接口時(shí),通過RSA加密和解密驗(yàn)證請(qǐng)求的有效性,在對(duì)接時(shí)雙方互換公鑰,需要的朋友可以參考下2023-12-12
springboot如何獲取相對(duì)路徑文件夾下靜態(tài)資源的方法
這篇文章主要介紹了springboot如何獲取相對(duì)路徑文件夾下靜態(tài)資源的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05
javaweb servlet中使用請(qǐng)求轉(zhuǎn)發(fā)亂碼的實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猨avaweb servlet中使用請(qǐng)求轉(zhuǎn)發(fā)亂碼的實(shí)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08
Java中的CopyOnWriteArrayList容器解析
這篇文章主要介紹了Java中的CopyOnWriteArrayList容器解析,CopyOnWriteArrayList容器允許并發(fā)讀,讀操作是無鎖的,性能較高。至于寫操作,比如向容器中添加一個(gè)元素,則首先將當(dāng)前容器復(fù)制一份,然后在新副本上執(zhí)行寫操作,需要的朋友可以參考下2023-12-12
一文搞懂SpringBoot如何利用@Async實(shí)現(xiàn)異步調(diào)用
異步調(diào)用幾乎是處理高并發(fā),解決性能問題常用的手段,如何開啟異步調(diào)用?SpringBoot中提供了非常簡單的方式,就是一個(gè)注解@Async。今天我們重新認(rèn)識(shí)一下@Async,以及注意事項(xiàng)2022-09-09

