在项目中用到了<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>