标签:mapper resultmap 遍历 arraylist pre ace interface sel select
在mapper
中传入数组或集合类,使用foreach
标签遍历出其中的值与SQL
语句拼接
JAVA dao
层接口
public interface UserDao {
public List<User> getUsersByCollection(Collection collection);
}
mapper
文件
<select id="getUsersByCollection" resultMap="userMapper">
select * from users where id in
<foreach collection="list" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
测试
@Test
public void getUsersByCollection() {
Collection collection = new ArrayList<Integer>();
collection.add(1);
collection.add(3);
collection.add(5);
List<User> users = userDao.getUsersByCollection(collection);
System.out.println(users);
}
标签:mapper resultmap 遍历 arraylist pre ace interface sel select
原文地址:https://www.cnblogs.com/esrevinud/p/12299195.html