如何使用MyBatis批量插入数据

 时间:2024-10-27 22:28:30

1、使用执行批量操作的sqlSession执行员工批量插入package com.gwolf.cru蟠校盯昂d.test;import java.util.UUID;import org.apache.ibatis.session.SqlSession;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.test.context.ContextConfiguration;import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;import com.gwolf.crud.bean.Employee;import com.gwolf.crud.dao.DepartmentMapper;import com.gwolf.crud.dao.EmployeeMapper;/*** 测试dao层的工作* @author CaoChuanPing**/@RunWith(SpringJUnit4ClassRunner.class)@ContextConfiguration(locations={"classpath:applicationContext.xml"})public class MapperTest { @Autowired private DepartmentMapper departmentMapper; @Autowired private SqlSession sqlSession; /** * 测试DeptmentMapper */ @Test public void testCRUD() { EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class); for(int i = 0 ;i < 10000;i++) { mapper.insertSelective(new Employee(null,UUID.randomUUID().toString().substring(0, 5) + i,"M","gwolf_2010@126.com",1)); } }}

如何使用MyBatis批量插入数据如何使用MyBatis批量插入数据

4、在测试方法中执行批量插入的方法。使用@Test public void testCRUD() { EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class); for(int i = 0 ;i < 10000;i++) { mapper.insertSelective(new Employee(null,UUID.randomUUID().toString().substring(0, 5) + i,"M","gwolf_2010@126.com",1)); } }

如何使用MyBatis批量插入数据

6、在mysql中查看数据是否插入成功了。

如何使用MyBatis批量插入数据
  • 更新驱动程序:[20]SD卡
  • 系统重装后没有网卡驱动,如何安装驱动
  • win101909无法完成更新正在撤销解决方法
  • 如何给自己的电脑装虚拟机
  • win10怎么关闭secure boot
  • 热门搜索
    眼睛模糊是怎么回事 我的世界打火石怎么做 二级钢筋符号怎么打 肺纹理增多是怎么回事 立面图怎么画 怎么查本机号码 火山是怎么形成的 流鼻血怎么处理 不知火舞怎么玩 羊排怎么做