默认全局配置文件
mybatis-config.xml
将sql映射文件注册到全局配置文件
<mappers>
<mapper resource="EmployeeBeanMapper.xml" />
</mappers>
1、读取配置文件,生成SqlSessionFactory
public SqlSessionFactory getSqlSessionFactory() throws IOException {
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
return new SqlSessionFactoryBuilder().build(inputStream);
}
2、获取sqlSession实例,能直接执行已经映射的sql语句
SqlSessionFactory sqlSessionFactory = getSqlSessionFactory();
SqlSession openSession = sqlSessionFactory.openSession();