在工作中遇到mybatis中判断两个集合是否为空,不为空的话遍历;都为空执行 1=0 or 1=0,则查询出来空集合 select login,name,email from users u where <choose> <when test="sameEmailList != null and sameEmailList.size > 0 "> email in <foreach collection="sameEmailList" item="email" open="(" separator="," close=")"> #{email, jdbcType=VARCHAR} </foreach> </when> <otherwise> 1 = 0 </otherwise> </choose> <choose> <when test="sameNameList != null and sameNameList.size > 0"> or name in <foreach collection="sameNameList" item="name" open="(" separator="," close=")"> #{name, jdbcType=VARCHAR} </foreach> </when> <otherwise> or 1 = 0 </otherwise> </choose> ORDER by name, email ASC
mybatis中判断两个集合是否为空
最新推荐文章于 2025-09-11 14:14:57 发布
在Mybatis中,为了根据两个集合(sameEmailList 和 sameNameList)的非空状态进行不同的SQL查询,可以使用`<choose>`标签结合`<when>`和`<otherwise>`来实现。如果集合不为空,则利用`<foreach>`遍历生成IN条件,反之如果集合都为空,则执行1=0的条件以返回空结果集。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
PyTorch 2.6
PyTorch
Cuda
PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理
7120

被折叠的 条评论
为什么被折叠?



