MyBatis 批量新增 修改

在这里插入图片描述
MyBatis批量新增
传入参数为List 类型
使用数据库为Oracle

mapper接口

void insertIntoYEAR(@Param("list")List<yearReportData> paramList);
  <insert id="insertIntoYEAR"  parameterType="java.util.List">
     
     		insert into	XSR_SIF_TRZ_YEARMONEY_PLAN	
    	   (
    	      ym_id,
    	      lastyear_plan_money,
    	      lastyear_actual_money,
    	      currentyear_plan_money,
    	      note,
    	      year_project_id,
    	      year_report_id,
    	      created_by,
    	      creation_date
    	    
    	   )	
		
			 
			  <foreach collection="list" item="item" index="index" separator="union all">		
			  
			  <trim prefix="select" suffix="from dual" suffixOverrides=",">	
			  <choose>
			  <when test="item.ym_id != null">#{item.ym_id,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose>
			  <choose>
			  <when test="item.lastyear_plan_money != null">#{item.lastyear_plan_money,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose>
			  <choose>
			  <when test="item.lastyear_actual_money != null">#{item.lastyear_actual_money,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose>
			  <choose>
			  <when test="item.currentyear_plan_money != null">#{item.currentyear_plan_money,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose>
			  <choose>
			  <when test="item.note!= null">#{item.note,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose><choose>
			  <when test="item.year_project_id != null">#{item.year_project_id,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose><choose>
			  <when test="item.year_report_id != null">#{item.year_report_id,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose><choose>
			  <when test="item.created_by != null">#{item.created_by,jdbcType=VARCHAR},</when>
			  <otherwise>null,</otherwise>
			  </choose>
			  sysdate,

			</trim>
			  </foreach>
			  
     
     
     </insert>

批量更新

void updateInOrOut(@Param("list")List<monthReportData> paramList);
<update id="updateInOrOut" parameterType="java.util.List">
    		
        <if test="list!=null">
            <foreach collection="list" item="item" index= "index" open="begin" close=";end;" separator=";">
            update XSR_SIF_TRZ_INOROUT
                <set>
                <if test="item.slastmonth_actual_money != null">slastmonth_actual_money=#{item.slastmonth_actual_money,jdbcType=VARCHAR},</if>
				<if test="item.scurrentmonth_plan_money != null">scurrentmonth_plan_money=#{item.scurrentmonth_plan_money,jdbcType=VARCHAR},</if>
				<if test="item.zlastmonth_actual_money != null">zlastmonth_actual_money=#{item.zlastmonth_actual_money,jdbcType=VARCHAR},</if>
				<if test="item.zcurrentmonth_plan_money != null">zcurrentmonth_plan_money=#{item.zcurrentmonth_plan_money,jdbcType=VARCHAR},</if>
				<if test="item.plan_year != null">plan_year=#{item.plan_year,jdbcType=VARCHAR},</if>
				<if test="item.plan_month != null">plan_month=#{item.plan_month,jdbcType=VARCHAR},</if>
				LAST_UPDATE_DATE = sysdate
				</set>
				where 1=1
				<if test="item.report_id != null">and report_id=#{item.report_id}</if>
				<if test="item.outproject_id != null">and outproject_id=#{item.outproject_id}</if>
				</foreach>
        </if>
       
    </update>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值