新增SQL:
<insert id="insertCorresponding" parameterType="java.util.List">
insert into tableName(
id,a,b,c,
create_time,update_time, is_delete
)values
<foreach collection="list" item="item" index="index" separator=",">
(
#{item.id},#{item.a},#{item.b}, #{item.c},
#{item.createTime},#{item.updateTime}, #{item.isDelete}
)
</foreach>
</insert>
修改SQL:
<!--检查数据库连接中有没有:allowMultiQueries=true 没有就加上,否则报错-->
<update id="updateDCCorresponding" parameterType="java.util.List">
<if test="list!=null">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update tableName
<trim prefix="set" suffixOverrides=",">
<if test="item.a!=null and item.a!=''">
a=#{item.a},
</if>
<if test="item.b!=null and item.b!=''">
b=#{item.b},
</if>
<if test="item.c!=null and item.c!=''">
c=#{item.c},
</if>
<if test="item.updateTime!=null and item.updateTime!=''">
update_time=#{item.updateTime},
</if>
<if test="item.isDelete!=null and item.isDelete!=''">
is_delete=#{item.isDelete},
</if>
</trim>
where
id=#{item.id,jdbcType=VARCHAR}
</foreach>
</if>
</update>
jdbcType可加可不加
加上jdbcType原因(网络): 当传入字段值为null,时,需要加入. 否则报错.
mybatis insert空值报空值异常,但是在pl/sql不会提示错误,主要原因是mybatis无法进行转换,是因为你传入的参数的字段为null对象无法获取对应的jdbcType类型,而报错误
版权声明:本文为weixin_43738469原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。