Bläddra i källkod

修复序列获取两次的bug.

其实是咩咩写的.
nieqiuqiu 5 år sedan
förälder
incheckning
96f0a8c4e6

+ 8 - 5
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/plugins/SqlExplainInterceptor.java

@@ -21,6 +21,7 @@ import org.apache.ibatis.executor.statement.StatementHandler;
 import org.apache.ibatis.logging.Log;
 import org.apache.ibatis.logging.LogFactory;
 import org.apache.ibatis.mapping.MappedStatement;
+import org.apache.ibatis.mapping.SqlCommandType;
 import org.apache.ibatis.plugin.Interceptor;
 import org.apache.ibatis.plugin.Intercepts;
 import org.apache.ibatis.plugin.Invocation;
@@ -56,11 +57,13 @@ public class SqlExplainInterceptor extends AbstractSqlParserHandler implements I
     public Object intercept(Invocation invocation) throws Throwable {
         Object[] args = invocation.getArgs();
         MappedStatement ms = (MappedStatement) args[0];
-        Object parameter = args[1];
-        Configuration configuration = ms.getConfiguration();
-        Object target = invocation.getTarget();
-        StatementHandler handler = configuration.newStatementHandler((Executor) target, ms, parameter, RowBounds.DEFAULT, null, null);
-        this.sqlParser(SystemMetaObject.forObject(handler));
+        if (ms.getSqlCommandType() == SqlCommandType.DELETE || ms.getSqlCommandType() == SqlCommandType.UPDATE) {
+            Object parameter = args[1];
+            Configuration configuration = ms.getConfiguration();
+            Object target = invocation.getTarget();
+            StatementHandler handler = configuration.newStatementHandler((Executor) target, ms, parameter, RowBounds.DEFAULT, null, null);
+            this.sqlParser(SystemMetaObject.forObject(handler));
+        }
         return invocation.proceed();
     }
 

+ 2 - 0
mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/h2/H2KeyGeneratorTest.java

@@ -2,6 +2,7 @@ package com.baomidou.mybatisplus.test.h2;
 
 import com.baomidou.mybatisplus.test.h2.keygenerator.mapper.KeyGeneratorMapper;
 import com.baomidou.mybatisplus.test.h2.keygenerator.model.KeyGeneratorModel;
+import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.MethodOrderer;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.TestMethodOrder;
@@ -23,6 +24,7 @@ class H2KeyGeneratorTest {
         KeyGeneratorModel keyGeneratorModel = new KeyGeneratorModel();
         keyGeneratorModel.setName("我举起了个栗子");
         keyGeneratorMapper.insert(keyGeneratorModel);
+        Assertions.assertNotNull(keyGeneratorModel.getId());
     }
 
 }