这篇文章主要介绍了MyBatis传入数组集合类并使用foreach遍历,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
在mapper中传入数组或集合类,使用foreach标签遍历出其中的值与SQL语句拼接
JAVA dao层接口
public interface UserDao { public ListgetUsersByCollection(Collection collection); }
mapper文件
测试
@Test public void getUsersByCollection() { Collection collection = new ArrayList(); collection.add(1); collection.add(3); collection.add(5); List users = userDao.getUsersByCollection(collection); System.out.println(users); }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。