mybatis批量更新:
形式一:
更新的时候带有判断条件的:
<!-- 添加数据权限后,数据补充。批量更新入库 -->
<update id="batechUpdateInfoForOaAuth" parameterType="list">
<foreach collection="aList" index="index" item="item" open="" close="" separator=";">
update a表
<set>
<if test="item.deptCode !=null">
dept_code = #{item.deptCode,jdbcType=VARCHAR},
</if>
<if test="item.deptName !=null">
dept_name = #{item.deptName,jdbcType=VARCHAR},
</if>
<if test="item.productLineCode !=null">
product_line_code = #{item.productLineCode,jdbcType=VARCHAR},
</if>
<if test="item.productLineName !=null">
product_line_name = #{item.productLineName,jdbcType=VARCHAR},
</if>
<if test="item.subjectCode !=null">
subject_code = #{item.subjectCode,jdbcType=VARCHAR},
</if>
<if test="item.subjectName !=null">
subject_name = #{item.subjectName,jdbcType=VARCHAR},
</if>
<if test="item.jobDeptCode !=null">
job_dept_code = #{item.jobDeptCode,jdbcType=VARCHAR},
</if>
<if test="item.jobDeptName !=null">
job_dept_name = #{item.jobDeptName,jdbcType=VARCHAR},
</if>
<if test="item.jobManagerName !=null">
job_manager_name = #{item.jobManagerName,jdbcType=VARCHAR},
</if>
<if test="item.financeType !=null">
finance_type = #{item.financeType},
</if>
</set>
where id = #{item.id}
</foreach>
</update>
形式二:直接更新
<!--添加数据权限后,结算数据补充。批量更新入库-->
<update id="batechUpdateSalarWayInfoForOaAuth" parameterType="java.util.List">
<foreach collection="bWayList" item="item" index="index" open="" close="" separator=";">
update b表
<set>
position_type = ${item.positionType}
</set>
where id = ${item.id}
</foreach>
</update>
如果直接这样写,有可能会出现问题的。因为:
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true" />
数据库连接需要添加:allowMultiQueries=true
有可能是下面这种情况: