Caratacus 6 лет назад
Родитель
Сommit
4b7f06abfc

+ 2 - 6
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/service/impl/ServiceImpl.java

@@ -163,15 +163,11 @@ public class ServiceImpl<M extends BaseMapper<T>, T> implements IService<T> {
         if (CollectionUtils.isEmpty(entityList)) {
             throw new IllegalArgumentException("Error: entityList must not be empty");
         }
-        Class<?> cls = null;
-        TableInfo tableInfo = null;
+        Class<?> cls = currentModelClass();
+        TableInfo tableInfo = TableInfoHelper.getTableInfo(cls);
         int i = 0;
         try (SqlSession batchSqlSession = sqlSessionBatch()) {
             for (T anEntityList : entityList) {
-                if (i == 0) {
-                    cls = anEntityList.getClass();
-                    tableInfo = TableInfoHelper.getTableInfo(cls);
-                }
                 if (null != tableInfo && StringUtils.isNotEmpty(tableInfo.getKeyProperty())) {
                     Object idVal = ReflectionKit.getMethodValue(cls, anEntityList, tableInfo.getKeyProperty());
                     if (StringUtils.checkValNull(idVal) || Objects.isNull(getById((Serializable) idVal))) {