mybatis批量insert或update,返回行数为-1

如果要拿到更新条数,修改如下:

在mybatis-config.xml配置:

<configuration>
    <settings>
        <setting name="defaultExecutorType" value="BATCH"/>
    </settings>
</configuration>
设置参数描述有效值默认值
defaultExecutorType配置默认的执行器。SIMPLE 就是普通的执行器;REUSE 执行器会重用预处理语句(prepared statements); BATCH 执行器将重用语句并执行批量更新。SIMPLE REUSE BATCHSIMPLE

但是,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 映射文件中,你可以使用 insertupdatedeleteselect 等语句指定不同的执行器类型:

<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()返回只有-优快云博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值