next,finish,等待创建完成,创建完成后,src/main下只有webapp文件夹,我们需要手动创建java和resources,鼠标右击main,new folder,将java改成Sources类型,resources变成Resources类型
引入项目依赖- spring
- springmvc
- mybatis
- 数据库连接池,驱动
- 其它(jstl,servlet-api,junit)
添加约束
配置spring,springmvc,字符过滤器,Restful URI
contextConfigLocation
classpath:applicationContext.xml
org.springframework.web.context.ContextLoaderListener
dispatcherServlet
org.springframework.web.servlet.DispatcherServlet
1
dispatcherServlet
/
CharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
utf-8
forceRequestEncoding
true
forceResponseEncoding
true
CharacterEncodingFilter
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:applicationContext.xml"})
public class MapperTest {
@Autowired
DepartmentMapper departmentMapper;
@Autowired
EmployeeMapper employeeMapper;
@Autowired
SqlSession sqlSession;
@Test
public void testCRUD(){
//1、插入几个部门
// departmentMapper.insertSelective(new Department(null, "开发部"));
// departmentMapper.insertSelective(new Department(null, "测试部"));
//2、生成员工数据,测试员工插入
//employeeMapper.insertSelective(new Employee(null, "Jerry", "M", "Jerry@atguigu.com", 2));
//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+"@163.com", 3));
}
System.out.println("批量完成");
}
}



