mybatis xml文件<!-- 批量更新 --> <update id="batchUpdate" parameterType="java.util.List"> <if test="list != null"> <foreach collection="list" item="item" index="index" open="begin" close="; end;" separator=";"> update REPORT_CHARGED_HOMEWORK <set > <if test="item.departmentName != null" > DEPARTMENT_NAME = #{item.departmentName,jdbcType=VARCHAR}, </if> <if test="item.workTicket != null" > WORK_TICKET = #{item.workTicket,jdbcType=VARCHAR}, </if> <if test="item.teamNumber != null" > TEAM_NUMBER = #{item.teamNumber,jdbcType=VARCHAR}, </if> <if test="item.responsiblePerson != null" > RESPONSIBLE_PERSON = #{item.responsiblePerson,jdbcType=VARCHAR}, </if> <if test="item.substation != null" > SUBSTATION = #{item.substation,jdbcType=VARCHAR}, </if> </set> where TEMPORARY_ID = #{item.temporaryId,jdbcType=VARCHAR} </foreach> </if> </update>service层 int i=ChargedHomeworkMapper.batchUpdate(list);经过debug模式调试发现 每次执行 批量更新的时候 返回值都为-1 这个为什么呢? 求各位大哥大姐帮帮忙
3 回答

Jimin
TA贡献6条经验 获得超1个赞
返回负数,是由于mybatis的defaultExecutorType的引起的,defaultExecutorType有三个执行器SIMPLE、REUSE和BATCH。
其中BATCH可以批量更新操作缓存SQL以提高性能,但是有个缺陷就是无法获取update、delete返回的行数
如果确定要拿到更新条数,defaultExecutorTypes设置成SIMPLE就可以
添加回答
举报
0/150
提交
取消