标签:tiny order name type mob 插入 values nbsp mobile
sql 1 批量插入
<insert id="batchInsert" useGeneratedKeys="true" parameterType="java.util.List" >
<selectKey resultType="long" keyProperty="id" order="AFTER">
SELECT
LAST_INSERT_ID()
</selectKey>
insert into user_contacts_info (id,user_id,old_id,cont_type,
cont_ship, cont_status, cont_source,
cont_user_name, cont_id_card, cont_mobile1,
cont_mobile2, cont_mobile3, cont_tell,
cont_addr, cont_addr_hk, cont_addr_com,
cont_tell_com, e_mail, remark, create_time,
cont_name_com,update_time)
values
<foreach collection="list" item="item" index="index" separator="," >
(#{item.id,jdbcType=INTEGER},#{item.userId,jdbcType=INTEGER},#{item.oldId,jdbcType=INTEGER}, #{item.contType,jdbcType=VARCHAR},
#{item.contShip,jdbcType=VARCHAR}, #{item.contStatus,jdbcType=VARCHAR}, #{item.contSource,jdbcType=VARCHAR},
#{item.contUserName,jdbcType=VARCHAR}, #{item.contIdCard,jdbcType=VARCHAR}, #{item.contMobile1,jdbcType=VARCHAR},
#{item.contMobile2,jdbcType=VARCHAR}, #{item.contMobile3,jdbcType=VARCHAR}, #{item.contTell,jdbcType=VARCHAR},
#{item.contAddr,jdbcType=VARCHAR}, #{item.contAddrHk,jdbcType=VARCHAR}, #{item.contAddrCom,jdbcType=VARCHAR},
#{item.contTellCom,jdbcType=VARCHAR},#{item.eMail,jdbcType=VARCHAR}, #{item.remark,jdbcType=VARCHAR},
#{item.createTime,jdbcType=TIMESTAMP}, #{item.contNameCom,jdbcType=VARCHAR},
#{item.updateTime,jdbcType=TIMESTAMP})
</foreach>
</insert>
sql 2 批量插入,表设置为主键自增长
<insert id="insertByBatch" parameterType="java.util.List">
insert into monitor_log
(monitor_id, monitor_date, monitor_stats,
monitor_info,
monitor_product_id, monitor_repair_date,
monitor_repair_userid)
values
<foreach collection="list" item="item" index="index"
separator=",">
(#{item.monitorId,jdbcType=INTEGER},
#{item.monitorDate,jdbcType=TIMESTAMP},
#{item.monitorStats,jdbcType=TINYINT},
#{item.monitorInfo,jdbcType=VARCHAR},
#{item.monitorProductId,jdbcType=INTEGER},
#{item.monitorRepairDate,jdbcType=TIMESTAMP},
#{item.monitorRepairUserid,jdbcType=INTEGER})
</foreach>
</insert>
sql 3 批量修改
<update id="updateBatch" parameterType="java.util.List">
update monitor_log
<trim prefix="set" suffixOverrides=",">
<trim prefix="monitor_date =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorDate !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorDate,jdbcType=TIMESTAMP}
</if>
</foreach>
</trim>
<trim prefix="monitor_stats =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorStats !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorStats,jdbcType=TINYINT}
</if>
</foreach>
</trim>
<trim prefix="monitor_info =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorInfo !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorInfo,jdbcType=VARCHAR}
</if>
</foreach>
</trim>
<trim prefix="monitor_product_id =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.monitorProductId !=null ">
when monitor_id=#{item.monitorId} then #{item.monitorProductId,jdbcType=INTEGER}
</if>
</foreach>
</trim>
where monitor_id in
<foreach collection="list" index="index" item="item"
separator="," open="(" close=")">
#{item.monitorId,jdbcType=BIGINT}
</foreach>
</update>
标签:tiny order name type mob 插入 values nbsp mobile
原文地址:http://www.cnblogs.com/zhaoblog/p/7521532.html