mybatis中mapper⽂件中sqlin的⽤法这⾥使⽤ foreach标签创业园区
朝鲜三国时代
<foreach item="item" collection="listTag" index="index" open="(" parator="," clo=")">
#{item}
</foreach>
foreach元素的属性主要有 item,index,collection,open,parator,clo。
item表⽰集合中每⼀个元素进⾏迭代时的别名.
index指定⼀个名字,⽤于表⽰在迭代过程中,每次迭代到的位置.
open表⽰该语句以什么开始,parator表⽰在每次进⾏迭代之间以什么符号作为分隔符.
clo表⽰以什么结束.
1.如果传⼊的是单参数且参数类型是⼀个List的时候,collection属性值为list
<lect id="addList" resultType="map">
started
lect * from tp_trade where id in
<foreach item="item" collection="list" index="index" open="(" parator="," clo=")">#{item}</foreach>
</lect>
传⼊参数的代码为:笨笨的爱
房子卡通图片List<Object> addList(List<Object> ids);
2.如果传⼊的是单参数且参数类型是⼀个Array数组的时候,collection属性值为array
<lect id="addArray" resultType="map">
班级管理心得体会
lect * from tp_trade where tt_type in
<foreach item="item" collection="array" index="index" open="(" parator="," clo=")">#{item}</foreach>
</lect>
传⼊的参数代码为:
List<Object> addArray(String[] ids);
3.如果多个参数,我们会封装成map类型,然后在把需要遍历的list或者array封装到map中。
传⼊的参数代码为:
String str = "1,2,3,4";
Map map = new HashMap();
map.put("type",str.spit(","));
再把封装好map传⼊到⽅法中。
List<Object> addMap(Map<String,Object> map);
<lect id="addMap" resultType="map">
lect * from tp_trade where type in
梦幻答题器网页版
弘扬延安精神
<foreach item="item" collection="type" index="index" open="(" parator="," clo=")">#{item}</foreach>
</lect>
type就是数组集合,使⽤item遍历即可。