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>