以下所有源码只截取了部分代码,标题即为类名

1、Web.xml

<filter-name>jfinal</filter-name>
<filter-class>com.jfinal.core.JFinalFilter</filter-class>

2、JFinalFilter

if (jfinal.init(jfinalConfig, filterConfig.getServletContext()) == false)

3、Jfinal

boolean init(JFinalConfig jfinalConfig, ServletContext servletContext) {

   Config.configJFinal(jfinalConfig); // start plugin and init log factory in this method

}

4、Config

static void configJFinal(JFinalConfig jfinalConfig) {

   jfinalConfig.configConstant(constants);             initLogFactory();

   jfinalConfig.configRoute(routes);

   jfinalConfig.configPlugin(plugins);                startPlugins();    // very important!!!

   jfinalConfig.configInterceptor(interceptors);

   jfinalConfig.configHandler(handlers);

}

加载jfinalConfig配置文件

5、jfinalConfig

public void configRoute(Routes me) {

   //增加自定义route

   me.add(new ApiRoute());

6、  Routes

public Routes add(Routes routes) {

   if (routes != null) {

      routes.config();   // very important!!!

      for (Entry<String, Class<? extends Controller>> e : routes.map.entrySet()) {

         String controllerKey = e.getKey();

         if (this.map.containsKey(controllerKey)) {

            throw new IllegalArgumentException("The controllerKey already exists: " + controllerKey); 

         }

         this.map.put(controllerKey, e.getValue());

         this.viewPathMap.put(controllerKey, routes.getViewPath(controllerKey));

      }

   }

   return this;

}

7、JFinalFilter

加载完jfinalConfig回到JFinalFilter

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {

try {

   handler.handle(target, request, response, isHandled);

}

// handler.handle(target, request, response, isHandled);是整个Filter最核心的方法

这里的handlre来自JFinalFilter.init方法中52行handler=jfinal.getHandler();

8、Jfinal

private void initHandler() {

   Handler actionHandler = new ActionHandler(actionMapping, constants);

   handler = HandlerFactory.getHandler(Config.getHandlers().getHandlerList(), actionHandler);

}

handler是由HandlerFactory的getHandler方法得来的,此处使用handler子类ActionHandler,并且传进去了有两个参数,一个是ActionMapping类的变量,一个是constants。

ActionMapping在ActionMapping中定义了一个路由(routes)和一个Interceptors,这个routes类里面主要的核心是两个Map,主要处理处理一些关于ActionMapping中对应的ControllerKey与Controller.class的事情。看下ActionHandler

9、ActionHandler

  1)、根据ActionMapping获得相应的Action,

Action action = actionMapping.getAction(target, urlPara);

  2)、然后利用反射进行方法的调用,最后把结果映射到相应的页面上去

new Invocation(action, controller).invoke();

最新文章

  1. 用游标实现查询当前服务器所有数据库所有表的SQL
  2. Linux mips64r2 PCI中断路由机制分析
  3. 在Windows和Linux上安装paramiko模块以及easy_install的安装方法
  4. Eclipse各种配置
  5. Zookeeper 服务注册和发现
  6. BZOJ4171 : Rhl的游戏
  7. Solaris 和linux 之oracle 数据库的安装
  8. svn出现权限不足时的解决方法
  9. POJ 2387 Til the Cows Come Home
  10. Xmpp integration with Asterisk
  11. xml有哪些解析技术?区别是什么?
  12. 一个很好的用C#导出数据到Excel模板的方法
  13. windows服务1053错误排查
  14. JVM运行和类加载过程
  15. 关于 DropDownList 循环绑定中遇到的问题
  16. robotframework自动化系列:随机下拉框
  17. 英语词汇(5)followed by / sung by / written by
  18. cdn帮助链接汇集
  19. Jenkins系列之四——设置邮件通知
  20. php与java通用AES加密解密算法

热门文章

  1. tomcat启动报错Several ports (8080, 8009) required by Tomcat v6.0
  2. PHP备忘录
  3. LeetCode 624. Maximum Distance in Arrays (在数组中的最大距离)$
  4. angular 1.5.3各种模块使用(一)
  5. Spring、SpringMVC、SpringData + JPA 整合详解
  6. TinyXML2的使用
  7. 【20171104中】chrome自动刷新网页
  8. js之学习正则表达式
  9. Flex 基础语法(二)
  10. G彩娱乐网一个程序员到一个销售高手的心路历程