|
@@ -15,6 +15,13 @@
|
|
|
*/
|
|
|
package com.baomidou.framework.service.impl;
|
|
|
|
|
|
+import java.io.Serializable;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.logging.Logger;
|
|
|
+
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
import com.baomidou.framework.service.IService;
|
|
|
import com.baomidou.mybatisplus.annotations.IdType;
|
|
|
import com.baomidou.mybatisplus.exceptions.MybatisPlusException;
|
|
@@ -25,12 +32,6 @@ import com.baomidou.mybatisplus.toolkit.CollectionUtil;
|
|
|
import com.baomidou.mybatisplus.toolkit.ReflectionKit;
|
|
|
import com.baomidou.mybatisplus.toolkit.TableInfo;
|
|
|
import com.baomidou.mybatisplus.toolkit.TableInfoHelper;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-
|
|
|
-import java.io.Serializable;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.logging.Logger;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -113,7 +114,24 @@ public class ServiceImpl<M extends BaseMapper<T, PK>, T, PK extends Serializable
|
|
|
}
|
|
|
|
|
|
public boolean insertBatch(List<T> entityList) {
|
|
|
- return retBool(baseMapper.insertBatch(entityList));
|
|
|
+ if (null == entityList) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ int total = entityList.size();
|
|
|
+ if (total <= 10) {
|
|
|
+ /*
|
|
|
+ * 设置 10 条内批量,超过循环提交,防止 SQL 超长。
|
|
|
+ */
|
|
|
+ return retBool(baseMapper.insertBatch(entityList));
|
|
|
+ }
|
|
|
+ int result = 0;
|
|
|
+ for (T t : entityList) {
|
|
|
+ result = baseMapper.insert(t);
|
|
|
+ if (result <= 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return retBool(result);
|
|
|
}
|
|
|
|
|
|
public boolean insertBatchSelective(List<T> entityList) {
|
|
@@ -123,6 +141,9 @@ public class ServiceImpl<M extends BaseMapper<T, PK>, T, PK extends Serializable
|
|
|
int result = 0;
|
|
|
for (T t : entityList) {
|
|
|
result = baseMapper.insertSelective(t);
|
|
|
+ if (result <= 0) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
return retBool(result);
|
|
|
}
|