这里我们的传参都是List<对象>,亲自测试可用,我发现网上很多Oracle的批量插入写法是错误的,所以就想贴出来,让大家少走一点弯路。
一、oracle写法
<insert id="insertBatchList" parameterType="java.util.List" > BEGIN <foreach collection="list" item="obi" separator=";"> insert into T_OS_BASIC_INFO (PROJECT_NAME, COMPANY_NAME, PROJECT_ID, WEBSITE, LOGO, INDUSTRY, PUBLISH_TIME, TAG, ADDRESS, PROJECT_INTRODUCTION, BRIEF_INTRODUCTION,CITY,DISTRICT) values (#{obi.projectName,jdbcType=VARCHAR}, #{obi.companyName,jdbcType=VARCHAR}, #{obi.projectId,jdbcType=VARCHAR}, #{obi.website,jdbcType=VARCHAR}, #{obi.logo,jdbcType=VARCHAR}, #{obi.industry,jdbcType=VARCHAR}, #{obi.publishTime,jdbcType=TIMESTAMP}, #{obi.tag,jdbcType=VARCHAR}, #{obi.address,jdbcType=VARCHAR}, #{obi.projectIntroduction,jdbcType=VARCHAR}, #{obi.briefIntroduction,jdbcType=VARCHAR}, #{obi.city,jdbcType=VARCHAR}, #{obi.district,jdbcType=VARCHAR}) </foreach> ;END; </insert>二、MySQL写法
<insert id="insertbatch" parameterType="java.util.List"> insert into t_djg_stock_change_details (t_date, t_code, t_c_name, t_e_name, change_ratio, change_man, stock_type, change_num, change_after, deal_price, change_reason, change_money, post) values <foreach collection="list" item="item" index="index" separator=","> (#{item.tDate,jdbcType=VARCHAR}, #{item.tCode,jdbcType=VARCHAR}, #{item.tCName,jdbcType=VARCHAR}, #{item.tEName,jdbcType=VARCHAR}, #{item.changeRatio,jdbcType=VARCHAR}, #{item.changeMan,jdbcType=VARCHAR}, #{item.stockType,jdbcType=VARCHAR}, #{item.changeNum,jdbcType=VARCHAR}, #{item.changeAfter,jdbcType=VARCHAR}, #{item.dealPrice,jdbcType=VARCHAR}, #{item.changeReason,jdbcType=VARCHAR}, #{item.changeMoney,jdbcType=VARCHAR}, #{item.post,jdbcType=VARCHAR}) </foreach> </insert>新闻热点
疑难解答