mybatis批量更新返回結果為-1,是由於mybatis的defaultExecutorType引起的,
它有三個執行器:SIMPLE 就是普通的執行器;REUSE 執行器會重用預處理語句(prepared statements); BATCH 執行器將重用語句並執行批量更新。
BATCH可以批量更新操作,緩存SQL以提高性能,缺陷就是無法獲取update、delete返回的行數。
如果要拿到更新條數,修改如下:
在mybatis-config.xml配置:
<configuration> <settings> <setting name="defaultExecutorType" value="SIMPLE"/> <setting name="defaultExecutorType" value="BATCH"/> </settings> </configuration>