码迷,mamicode.com
首页 > 数据库 > 详细

mybatis怎么批量插入或者更新数据库

时间:2018-05-28 11:47:21      阅读:644      评论:0      收藏:0      [点我收藏+]

标签:air   ace   des   参数   插入   .sh   list   maxheight   long   

批量插入格式示例:

<insert id="insertAirspaceList" parameterType="java.util.List" >
insert into airspace(name, code, type, shape_type, min_height, max_height, limitation_type, status,is_deleted, is_usable,shape_description)
VALUES
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.name,jdbcType=VARCHAR},
#{item.code,jdbcType=VARCHAR},
#{item.type,jdbcType=BIT},
#{item.shapeType,jdbcType=SMALLINT},
#{item.minHeight,jdbcType=INTEGER},
#{item.maxHeight,jdbcType=DOUBLE},
#{item.limitationType,jdbcType=SMALLINT},
#{item.status,jdbcType=TINYINT},
#{item.isDeleted,jdbcType=TINYINT},
#{item.isUsable,jdbcType=TINYINT},
#{item.shapeDescription,jdbcType=LONGVARCHAR})
</foreach>
</insert>

 

批量更新示例:

list包含四个参数:id,sendCompleteTime,failCause,status

<update id="updateSendFaxLogList" parameterType="java.util.List">
update send_fax_log
set send_complete_time =
<foreach collection="list" item="item" index="index"
separator=" " open="case id" close="end,">
when #{item.id} then #{item.sendCompleteTime,jdbcType=TIMESTAMP}
</foreach>
fail_cause =
<foreach collection="list" item="item" index="index"
separator=" " open="case id" close="end,">
when #{item.id} then #{item.failCause,jdbcType=VARCHAR}
</foreach>
status =
<foreach collection="list" item="item" index="index"
separator=" " open="case id" close="end">
when #{item.id} then #{item.status,jdbcType=TINYINT}
</foreach>
where id in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.id,jdbcType=INTEGER}
</foreach>
</update>

mybatis怎么批量插入或者更新数据库

标签:air   ace   des   参数   插入   .sh   list   maxheight   long   

原文地址:https://www.cnblogs.com/liuruilongdn/p/9098782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!