mybatis if test 不为空字符串或null的解决
更新时间:2022年11月30日 14:50:44 作者:在奋斗的大道
这篇文章主要介绍了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判断数值字符串注意项
<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 判断数值字符串注意项
if test 判断是否为某一数值字符串时需在数值字符串后加上toString()方法
如:
<if test="isInterrupt == '1'.toString() ">
2. Mybatis中遍历list入参
此处还有个知识点是mybatis使用foreach标签来遍历入参list。
如:
<if test="isInterrupt == '1'.toString() ">
AND A.basic_id IN (
<foreach collection="cutList" item="item" index="index" separator="," >
#{item}
</foreach>
)
</if>collection为需遍历数组,item为当前循环的变量,index为计数器,separator=","指循环一次则以“,”分隔
这里IN 的()可以直接用open="(" close=")"属性设置
<foreach collection="cutList" item="item" index="index" open="(" close=")" separator="," >总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
Java中的CopyOnWriteArrayList容器解析
这篇文章主要介绍了Java中的CopyOnWriteArrayList容器解析,CopyOnWriteArrayList容器允许并发读,读操作是无锁的,性能较高。至于写操作,比如向容器中添加一个元素,则首先将当前容器复制一份,然后在新副本上执行写操作,需要的朋友可以参考下2023-12-12
一文搞懂SpringBoot如何利用@Async实现异步调用
异步调用几乎是处理高并发,解决性能问题常用的手段,如何开启异步调用?SpringBoot中提供了非常简单的方式,就是一个注解@Async。今天我们重新认识一下@Async,以及注意事项2022-09-09


最新评论