package cn.com.cmbc.crud.test; import cn.com.cmbc.crud.bean.Department; import cn.com.cmbc.crud.bean.Employee; import cn.com.cmbc.crud.dao.DepartmentMapper; import cn.com.cmbc.crud.dao.EmployeeMapper; 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 java.util.UUID; /** *测试dao层的工作 * Created by yemin on 2017/8/26. * 使用spring的单元测试,可以自动注入我们的组件 * 需要在pom中导入spring单元测试的插件 * @ContextConfiguration指定spring配置文件的位置,可以不使用原生写法,直接指定autowired即可 */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations={"classpath:applicationContext.xml"}) public class MapperTest { @Autowired DepartmentMapper departmentMapper; @Autowired EmployeeMapper employeeMapper; @Autowired SqlSession sqlSession; @Test public void testCRUD(){ /* System.out.println(departmentMapper); departmentMapper.insertSelective(new Department(null,"开发部门")); departmentMapper.insertSelective(new Department(null,"测试部门")); // 生成员工数据,插入数据库 employeeMapper.insertSelective(new Employee(null, "gl", "M", "stream_gao@qq.com", 1)); employeeMapper.insertSelective(new Employee(null,"zhangsan","F","123@126.com",2));*/ //批量插入多个员工,批量,使用可以进行批量的sqlsession EmployeeMapper em= sqlSession.getMapper(EmployeeMapper.class); for(int i=0;i<1000;i++){ String uid= UUID.randomUUID().toString().substring(0,5)+i; em.insertSelective(new Employee(null, uid, "M", uid+"@126.com", 1)); } } }
测试mapper的工作
最新推荐文章于 2024-04-15 17:53:55 发布