创建SqlSessionFactory实例
使用xml创建SqlSessionFactory实例
String resource="mybatisConfig.xml";
Reader reader= Resources.getResourceAsReader(resource);
SqlSessionFactory sqlmapper = new SqlSessionFactoryBuilder().build(reader);
不使用xml创建SqlSessionFactory实例
TransactionFactory transactionFactory=new JdbcTransactionFactory();
Environment environment=new Environment("development",transactionFactory, new ConnectionH2());
Configuration configuration=new Configuration(environment);
configuration.addMapper(BlogMapper.class);
SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(configuration);
SqlSession sqlSession= sqlSessionFactory.openSession();
获取Session
SqlSession session=sqlmapper.openSession();