亚洲国产第一_开心网五月色综合亚洲_日本一级特黄特色大片免费观看_久久久久久久久久免观看

Hello! 歡迎來到小浪云!


MyBatis 批量插入時攔截器失效的原因是什么?


avatar
小浪云 2024-11-10 180

MyBatis 批量插入時攔截器失效的原因是什么?

mybatis批量插入時攔截器失效的原因

使用mybatis時,批量插入數據可能會導致攔截器失效。這是因為在執行批量插入時,mybatis會使用statementhandler執行更新,而不是executor。默認情況下,攔截器只攔截executor上的update方法,因此不會被觸發。

解決方法

要解決這個問題,需要在@intercepts注解中添加statementhandler.update方法的簽名,以確保攔截器可以攔截批量插入。修改后的攔截器如下:

@Component @Intercepts({         @Signature(type = Executor.class,method = "update",args = {MappedStatement.class, Object.class}),         @Signature(type = StatementHandler.class,method = "update",args = {Statement.class}) }) public class MyBatisAutoFillPlugin implements Interceptor {     // some code... }
登錄后復制

相關閱讀