jfinal 运行机制,我的理解

时间:2022-08-07 18:20:03
入口:

JFinalFilter  中

private Handler handler;  //子类中的ActionHandler.actionMapping包装了  链接跟具体某个方法的对应关系(action),handle方法里面的ActionInvocation包装了Interceptor[],Controller


public void init(FilterConfig filterConfig)throws ServletException {

createJFinalConfig(filterConfig.getInitParameter("configClass"));

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

thrownew RuntimeException("JFinal init error!");

handler = jfinal.getHandler();

constants = Config.getConstants();

encoding = constants.getEncoding();

jfinalConfig.afterJFinalStart();

String contextPath = filterConfig.getServletContext().getContextPath();

contextPathLength = (contextPath ==null ||"/".equals(contextPath) ? 0 : contextPath.length());

}


然后 去看  (jfinal.init  

private ActionMapping actionMapping;  //类似于/blog/update=com.jfinal.core.Action@91cd9ec

boolean init(JFinalConfig jfinalConfig, ServletContext servletContext) {

this.servletContext = servletContext;

this.contextPath = servletContext.getContextPath();

initPathUtil();

Config.configJFinal(jfinalConfig);// startplugin and init logger factory in this method

constants = Config.getConstants();

initActionMapping();

initHandler();

initRender();

initOreillyCos();

initTokenManager();

returntrue;

}



重点去看initActionMapping()

private void initActionMapping() {

actionMapping = new ActionMapping(Config.getRoutes(), Config.getInterceptors());

actionMapping.buildActionMapping();

}

buildActionMapping()这边初始话的时候  就把所有的处理器 (handle) 和 访问地址一一对应,并且   handle中的拦截器  都通过Config.getInterceptors()传递过去了