如何在 MyBatis 中 foreach 数组

how to foreach array in MyBatis

这是数组:

String[] user_login_array={user_email,user_password};

这是mybatis.xml:

<select id="getUser" parameterType="String"resultType="post.User">
     select * from users where user_email=#{user_email} and user_password=#{user_password}
</select>

如何将数组的参数添加到此 SQL?

这是我首先想到的。请看下面的逻辑,您实际上是在遍历数组并使用多个 AND 和 OR 来处理查询。这可能不是您的完美查询,但希望这能让您对实际解决方案有所了解。

<select id="getUser" parameterType="String"resultType="post.User"> 
select * from users where    
          <foreach item="item" collection="user_login_map.entrySet()" separator="OR">
        (user_email=#{item.key} AND user_password=#{item.value})
        </foreach>
</select>