- mapepr ```java
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import info.andav.boot.entities.BatchInsertTestTableEntities;
/**
- @author anda
- @since 1.0
*/
public interface BatchInsertTestTableMapper extends BaseMapper
{ }
- controller
```java
private static List<BatchInsertTestTableEntities> batchList = new ArrayList();
private final BatchInsertTestTableService batchInsertTestTableService;
static {
for (int i = 0; i < 1000; i++) {
BatchInsertTestTableEntities batchInsertTestTableEntities = new BatchInsertTestTableEntities();
batchInsertTestTableEntities.setPassword("root" + i);
batchInsertTestTableEntities.setUsername("gaosheng" + i);
batchInsertTestTableEntities.setCreateTime(LocalDateTime.now());
batchInsertTestTableEntities.setUpdateTime(LocalDateTime.now());
batchList.add(batchInsertTestTableEntities);
}
}
1.循环代码的操作
1.controller
/**
* 循环操作代码
* 109442ms 1000条数据耗时
*/
@GetMapping("/insert1")
public void insert1() {
long start = System.currentTimeMillis();
batchList.forEach(batchInsertTestTableService::insert);
long end = System.currentTimeMillis();
System.out.println("耗时 " + (end - start) + "ms");
}
2.service_impl
/**
* @author anda
* @since 1.0
*/
@Service
@RequiredArgsConstructor
public class BatchInsertTestTableServiceImpl extends ServiceImpl<BatchInsertTestTableMapper, BatchInsertTestTableEntities> implements BatchInsertTestTableService {
public void insert(BatchInsertTestTableEntities batchInsertTestTableEntities) {
batchInsertTestTableMapper.insert(batchInsertTestTableEntities);
}
}
3.service
public interface BatchInsertTestTableService {
void insert(BatchInsertTestTableEntities batchInsertTestTableEntities);
}