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", "[email protected]", 1)); employeeMapper.insertSelective(new Employee(null,"zhangsan","F","[email protected]",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的工作
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.