记录:419
场景:使用
MyBatis
的
标签
的
循环
遍历
List
类型的入参。使用collection属性指定
List
,item指定
List
中
存放的对象,separator指定分割符号,open指定开始字符,close指定结束字符。
<insert id="saveBatch"
parameterType="cn.net.polyinfo.entity.websitemanage.websiteWhite.TSiteWhiteEntity">
insert into t_site_white
`
list
id`,
`url`,
`name`,
`department`,...
select * from table where id in
<
foreach
collection="ids" open="(" close=")" separator="," item="item">
#{item}
</
foreach
>
foreach
的主要用在构建in条件
中
,它可以在
SQL语句
中
进行迭代一个集合。
foreach
元素的属性主要有 item,index,collection,open,separator,close。
item表示集合
中
每一个元素进行迭代时的别名,
index指定一个名字...
foreach
也就是
遍历
迭代,在SQL
中
通常用在 in 这个关键词的后面
foreach
元素的属性主要有item,index,collection,open,separator,close。
分别代表:
item表示集合
中
每一个元素进行迭代时的别名,
index用于表示在迭代过程
中
,每次迭代到的位置,
open表示该语句以什么开始,
separator表示在每次进行迭代之间以什么符号作为分隔符,
close表示以什么结束
代码片段:
<selectid="select...
将jdbc改写为
mybatis
时,传入的条件为
list
使用到的
标签
是<where>、<choose>、<when>、<if>、<
foreach
>因为判断
list
集合时判断条件不全,导致sql执行错误,下面是正确的判断条件
<where> <choose> <when tes...
update tb_dm_shoping set uip='996' where userId in
<if test="
list
!=null and
list
.size()>0">
<
foreach
collection="
list
" index="index" item="item" open="(" separator="," c...
Foreach
标签
中
,主要是collection、item、open、close、separate,collection指的是传入的集合名字,item指的是
遍历
出来的每个项的名字,open是指开始的符号,close是指结束的符号,separate是指各个项的连接符号
上面执行出来的
SQL语句
如下图所示:
open就是SQL拼接的开始符号,也就是“(”),close就是SQL拼接的结束符号,也就是“)”),separate就是SQL拼接的连接符号,也就是“or”,可视情况在开始符号加入“and”,..