目录
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession sqlSession = sqlSessionFactory.openSession();
List list = sqlSession.selectList("com.foo.bean.BlogMapper.queryAllBlogInfo");
创建Configuration对象
MyBatis初始化时会执行SqlSessionFactoryBuilder中的build()方法,build方法调XMLConfigBuilder()的parse()方法返回Configuration对象。
public Configuration parse() {
if (parsed) {
throw new Bu