ibatis批量插入、批量修改

1、批量修改,比如mysql中执行批量修改的脚本语句:

update zwt_workbench_app 

set rank = case app_id

when 1 then 20

when 2 then 21

when 3 then 22

end,

set mod_id = case app_id

when 1 then 3

when 2 then 4

when 3 then 5

end

where app_id in (1,2,3)

那么转成ibatis的写法如下: 

<update id="zwtWorkbench.updateAppInfoRank" parameterClass="java.util.List">
update zwt_workbench_app
set 
rank = case app_id
<iterate conjunction ="" open ="" close ="">
<![CDATA[
when #list[].appId# then #list[].rank#
]]> 
</iterate>
end,
mod_id = case app_id
<iterate conjunction ="" open ="" close ="">
<![CDATA[
when #list[].appId# then #list[].modId#
]]> 
</iterate>
end
where 
app_id in 
(
<iterate conjunction ="," open ="" close ="">
<![CDATA[
#list[].appId#
]]> 
</iterate>

</update>

2、批量插入在mysql中的执行sql脚本如下:

insert into hm_um_gray_user(custom_id,real_name,create_time,create_by)  values (1,'name',2017-07-26,'admin'),(2,'name2',2017-07-26,'admin2')

那么转成ibatis的写法如下:

<insert id="hm_um_gray_user_self.insertList" parameterClass="java.util.List">
insert into 
hm_um_gray_user(custom_id,real_name,create_time,create_by) 
VALUES
<iterate conjunction ="," open ="" close ="">
<![CDATA[ (
#list[].customId#,#list[].realName#,#list[].createTime#,#list[].createBy#
)
]]> 
</iterate>

</insert>

猜你喜欢

转载自blog.csdn.net/qq5132834/article/details/84765684
今日推荐