在工作中遇到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的条件以返回空结果集。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Dify
AI应用
Agent编排
Dify 是一款开源的大语言模型(LLM)应用开发平台,它结合了 后端即服务(Backend as a Service) 和LLMOps 的理念,让开发者能快速、高效地构建和部署生产级的生成式AI应用。 它提供了包含模型兼容支持、Prompt 编排界面、RAG 引擎、Agent 框架、工作流编排等核心技术栈,并且提供了易用的界面和API,让技术和非技术人员都能参与到AI应用的开发过程中
7121

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



