说明
项目框架Spring Boot(web模块) + Dubbo(service模块) + JSP(web页面)
MyBatis源码版本:3.4.5
个人理解,不全面
步骤
启动service模块,根据dao的个数,动态生成代理类
- org.apache.ibatis.binding.MapperRegistry#addMapper方法
- org.apache.ibatis.binding.MapperRegistry#getMapper方法
- org.apache.ibatis.binding.MapperProxyFactory#newInstance(org.apache.ibatis.session.SqlSession)方法
- org.apache.ibatis.binding.MapperProxyFactory#newInstance(org.apache.ibatis.binding.MapperProxy)方法
启动web模块,访问页面
进入Handler的业务方法,调用count方法
int countPutOnRecords(Map map);
定位到invoke方法
org.apache.ibatis.binding.MapperProxy#invoke
走到cachedMapperMethod方法,并进入
invoke方法的58行 final MapperMethod mapperMethod = cachedMapperMethod(method);,
根据key从map中取,没有的话,则创建,并放入map中
走到execute方法,并进入
invoke方法的59行 return mapperMethod.execute(sqlSession, args);
走到selectOne方法,进入方法
execute方法的82行 result = sqlSession.selectOne(command.getName(), param);