在项目中用到了<choose>进行判断,代码如下:
select name, email from users WHERE <choose> <when test=" null != list and list.size > 0"> email in <foreach collection="list" item="email" open="(" separator="," close=")"> #{email} </foreach> </when> <when test = " 'email' == type and '' != type"> ******* </when> </choose>mybatis中 if test的使用:
select name, email from users WHERE<if test=" null != list && list.size > 0 "> email in <foreach collection="list" item="email" open="(" separator="," close=")"> #{email} </foreach> </if>
本文介绍了一种使用MyBatis实现复杂条件查询的方法,通过<choose>和<if>标签来构建动态SQL,实现了根据不同参数进行灵活查询的功能。
3660

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



