Mapper.xml
<update id="updateByMultiConditions" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="begin" close="; end;" separator=";">
update TB_DUTY
<set>
<if test="item.morningPeopleIds != null and item.morningPeopleIds != '' " >
MORNING_PEOPLE_IDS=#{item.morningPeopleIds,jdbcType=VARCHAR},
</if>
<if test="item.morningPeopleNames != null and item.morningPeopleNames != '' " >
MORNING_PEOPLE_NAMES=#{item.morningPeopleNames,jdbcType=VARCHAR},
</if>
<if test="item.afternoonPeopleIds != null and item.afternoonPeopleIds != '' " >
AFTERNOON_PEOPLE_IDS=#{item.afternoonPeopleIds,jdbcType=VARCHAR},
</if>
<if test="item.afternoonPeopleNames != null and item.afternoonPeopleNames != '' " >
AFTERNOON_PEOPLE_NAMES=#{item.afternoonPeopleNames,jdbcType=VARCHAR},
</if>
<if test="item.eveningPeopleIds != null and item.eveningPeopleIds != '' " >
EVENING_PEOPLE_IDS=#{item.eveningPeopleIds,jdbcType=VARCHAR},
</if>
<if test="item.eveningPeopleNames != null and item.eveningPeopleNames != '' " >
EVENING_PEOPLE_NAMES=#{item.eveningPeopleNames,jdbcType=VARCHAR},
</if>
<if test="item.leaderIds != null and item.leaderIds != '' " >
LEADER_IDS=#{item.leaderIds,jdbcType=VARCHAR},
</if>
<if test="item.leaderNames != null and item.leaderNames != '' " >
LEADER_NAMES=#{item.leaderNames,jdbcType=VARCHAR},
</if>
</set>
where DUTY_ID=#{item.dutyId,jdbcType=INTEGER}
</foreach>
</update>
Controller:
int resultFlag=dutyService.updateByMultiConditions(dutyList2);
问题:
批量修改成功后返回的值是resultFlag=-1,作何解释?如何才能获得修改的行数?
遇到了同样的问题,返回-1好像就代表执行SQL成功
insert,返回值是:新插入行的主键(primary key);需要包含语句,才会返回主键,否则返回值为null。
update/delete,返回值是:更新或删除的行数;无需指明resultClass;但如果有约束异常而删除失败,只能去捕捉异常。
insert返回的是插入的行数啊!如下图:
delete返回值是删除的行数没错,唯独update返回的不是修改的行数。**怎么才能得到修改的行数?我想知道这个。**
目前我的确是采用异常捕捉的方式来处理。
继续等待高手指教。。。。。。