保存并判断字段是否为空
<insert id="saveBatch" parameterType="com.mct.MctBean">
<foreach collection="beanList" item="bean" index="index" open="" close="" separator=";">
insert into mct_factors
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="bean.id != null and bean.id != ''">
id,
</if>
<if test="bean.state != null and bean.state != ''">
state,
</if>
<if test="bean.createTime != null">
create_time,
</if>
<if test="bean.createId != null and bean.createId != ''">
create_id,
</if>
<if test="bean.updateTime != null">
update_time,
</if>
<if test="bean.updateId != null and bean.updateId != ''">
update_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="bean.id != null and bean.id != ''">
</if>
<if test="bean.state != null and bean.state != ''">
</if>
<if test="bean.createTime != null">
</if>
<if test="bean.createId != null and bean.createId != ''">
</if>
<if test="bean.updateTime != null">
</if>
<if test="bean.updateId != null and bean.updateId != ''">
</if>
</trim>
</foreach>
</insert>
批量写入数据有则修改无则新增,同时判断空选择性写入字段
<insert id="saveBatch" parameterType="com.mct.MctBean">
insert into mct_factors
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id!= null"> id, </if>
<if test="name != null"> name, </if>
</trim>
values
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id!= null">
<if test="name != null">
</trim>
ON DUPLICATE KEY UPDATE
<trim suffixOverrides=",">
<if test="id!= null"> id=
<if test="name != null"> name =
</trim>
</insert>
批量更新
<update id="updateBatch">
<foreach collection="beanList" item="bean" index="index" open="" close="" separator=";">
update mct_center_income_forecast_y
<trim suffixOverrides=",">
<set>
<if test="bean.name!= null and bean.name!= ''">
name=
</if>
</set>
</trim>
<trim suffixOverrides=",">
where id =
</trim>
</foreach>
</update>