public class UserMapperTest {
@Test
public void testQueryUserById() throws IOException {
String resource ="mybatis/mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
SqlSession sqlSession = sqlSessionFactory.openSession(true);
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
User user = userMapper.queryUserById(1l);
System.out.println(user);
}
}
接上篇mybatis内部运行原理
跟踪sqlSession.getMapper(UserMapper.class)方法:;来到接口SqlSession的实现类SqlSessionTemplate
public <T> T getMapper(Class<T> type) {
return getConfiguration().getMapper(type, this);
}
定位到configuration.getMapper(type, this),来到类Configuration
public <T>