MyBatis的foreach语句详解
来源:互联网 发布:bbc有声双语新闻软件 编辑:程序博客网 时间:2024/04/30 23:21
MyBatis的foreach语句详解
foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合。foreach元素的属性主要有item,index,collection,open,separator,close。item表示集合中每一个元素进行迭代时的别名,index指定一个名字,用于表示在迭代过程中,每次迭代到的位置,open表示该语句以什么开始,separator表示在每次进行迭代之间以什么符号作为分隔符,close表示以什么结束,在使用foreach的时候最关键的也是最容易出错的就是collection属性,该属性是必须指定的,但是在不同情况下,该属性的值是不一样的,主要有一下3种情况:
1.
2.
3.
下面分别来看看上述三种情况的示例代码:
1.单参数List的类型:
上述collection的值为list,对应的Mapper是这样的
List<Integer> ids = newArrayList<Integer>();
2.单参数array数组的类型:
上述collection为array,对应的Mapper代码:
2.单参数array数组的类型:
上述collection为array,对应的Mapper代码:
上述collection的值为ids,是传入的参数Map的key,对应的Mapper代码:
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- MyBatis的foreach语句详解
- 减小数组
- EditText属性
- VC程序运行时导出资源、DLL、EXE
- 海量数据挖掘MMDS week3:流算法Stream Algorithms
- TIME_WAIT是什么?
- MyBatis的foreach语句详解
- Maven:mirror和repository 区别
- swift基础知识<一>
- 路漫漫其修远兮~~~
- 封装好的网络请求类
- 结构体的嵌套问题
- 全排列问题
- 从25匹马中选5匹最快马
- Windows 命名管道 + 异步I/O模型