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>