这节我们来测试下我们生成的逆向工程是否合理吧!
这时我们来采用spring自带的test测试来完成!
test.java:
package com.yiyi.crud.utils;
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.yiyi.crud.bean.Department;
import com.yiyi.crud.bean.Employee;
import com.yiyi.crud.dao.DepartmentMapper;
import com.yiyi.crud.dao.EmployeeMapper;
/**
*
* @Title: Test.java
* @Package com.yiyi.crud.utils
* @Description: 测试类
* @author zww
* @date 2017年5月9日 下午11:26:58
* @version V1.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
public class Test {
@Autowired
private DepartmentMapper departmentMapper;
@Autowired
private EmployeeMapper employeeMapper;
@Autowired
private SqlSession sqlSession;
/**
* 测试DepartmentMapper
*/
@Test
public void testCRUD() {
// 1、插入几个部门
departmentMapper.insertSelective(new Department(null, "运维部"));
departmentMapper.insertSelective(new Department(null, "测试部"));
// //2、生成员工数据,测试员工插入
employeeMapper.insertSelective(new Employee(null, "zww", "M", "zww@yiyi.com", 6));
// 3、批量插入多个员工;批量,使用可以执行批量操作的sqlSession。
EmployeeMapper mapper = sqlSession.getMapper(EmployeeMapper.class);
for (int i = 0; i < 1000; i++) {
String uid = UUID.randomUUID().toString().substring(0, 5) + i;
mapper.insertSelective(new Employee(null, uid, "M", uid + "@yiyi.com", 10));
System.out.println("查看批量完成是否结束!");
}
}
}
这时来查下数据库相应的数据已经生成,接下里你们也来试试吧!