如果要拿到更新条数,修改如下:
在mybatis-config.xml配置:
<configuration>
<settings>
<setting name="defaultExecutorType" value="BATCH"/>
</settings>
</configuration>
设置参数 | 描述 | 有效值 | 默认值 |
defaultExecutorType | 配置默认的执行器。SIMPLE 就是普通的执行器;REUSE 执行器会重用预处理语句(prepared statements); BATCH 执行器将重用语句并执行批量更新。 | SIMPLE REUSE BATCH | SIMPLE |
但是,defaultExecutorType
只能设置为一个值,不支持设置多个。如果你想要设置多种执行器类型,你需要为不同的 mapper
或者 namespace
指定不同的 ExecutorType
。
在 MyBatis 配置文件中,你可以这样为不同的 mapper
指定不同的执行器类型:
<configuration>
<!-- 其他配置 -->
<mappers>
<mapper resource="path/to/YourMapper.xml" executorType="SIMPLE"/>
<mapper resource="path/to/AnotherMapper.xml" executorType="REUSE"/>
</mappers>
</configuration>
在 MyBatis 映射文件中,你可以使用 insert
, update
, delete
, select
等语句指定不同的执行器类型:
<mapper namespace="com.example.YourMapper">
<insert id="insertSelective" executorType="SIMPLE">
<!-- 插入语句 -->
</insert>
<select id="selectByExample" executorType="REUSE">
<!-- 查询语句 -->
</select>
</mapper>
请注意,executorType
属性只能在 MyBatis 配置文件或映射文件中设置,不能通过编程方式动态设置。
参考:mybatis的setting配置_configurationcustomizer-优快云博客
《Spring事务的陷阱(3)》中的现象与myBatis的执行器参数_defaultexecutortype-优快云博客
mybatis批量update,返回行数为-1_mybatis-plus 批量更新 sqlsession.flushstatements()返回只有-优快云博客