简单涉及以下几个类:
PageHelper PageMethod PageParam
PageInterceptor implement Interceptor
PageHelperAutoConfiguration implements EnvironmentAware
主要逻辑
启动系统时,
1.因为PageInterceptor实现了Interceptor,所以系统会初始化PageInterceptor.setProperties(Properties properties)方法,
注:@Signature注解对应的Executor.query的两个方法,当PageHelper生效后,将拦截这两个方法对应的Mapper映射器方法
2.PageHelperAutoConfiguration.addPageInterceptor()上有@PostCOnstruct注解,所以会初始化此方法,
将interceptor加入当前sqlSesson拦截器列表中
调用PageHelper.startPage(pageNum,pageSize)时,
1.系统会拦截到第一个Mapper查询数据的get方法,因为该方法最终是通过Executor.query执行
2.拦截到该方法后,加入分页逻辑,当执行完sql返回结果后,pageHelper(通过pageMethod)清空分页缓存
======================================================================================
Mapper初始化操作是通过MapperProxy处理的
======================================================================================
原文:https://www.cnblogs.com/qlsty/p/14302542.html