简体   繁体   English

如何在MyBatis中获取数组

[英]how to foreach array in MyBatis

this is array: 这是数组:

String[] user_login_array={user_email,user_password};

this is mybatis.xml : 这是mybatis.xml

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

How to add array's parameters to this SQL? 如何将数组的参数添加到此SQL?

This is something which I got first into mind. 这是我首先想到的。 Please see the below logic, where you are actually looping over the array and using multiple AND and OR to tackle the query. 请参阅下面的逻辑,您实际上是在数组上循环并使用多个AND和OR来处理查询。 This may not be the perfect query for you but hope this will give you some insights to the actual solution. 对于您来说,这可能不是完美的查询,但希望它能为您提供一些实际解决方案的见解。

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM