MyBatis 源码篇-SQL 执行的流程
本章通过一个简单的例子,来了解 MyBatis 执行一条 SQL 语句的大致过程是怎样的。 案例代码如下所示: public class MybatisTest { @Test public void selectByPrimaryKey() throws IOException { // 3 StudentDao studentDao = getSqlSession().getMapper(StudentDao.class); // 4 Student student = studentDao.selectByPrimaryKey(1L); System.out.println(student); } /** * 获取SqlSession * * @return */ private SqlSession getSqlSession() throws IOException { // 1 InputStream in = Resources.getResourceAsStream("mybatis-config.xml"); SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(in); // 2 return sqlSessionFactory.openSession(true);