May 14, 2021 JFinal manual
The Before annotation is used to configure the interceptor, which can be configured with Class, Method-level interceptors, and the following is an example of code:
As shown in the previous code, Before can configure the interceptor to be class-level, which blocks all methods in this class, and Method-level, which intercepts only this method. In addition, Before can configure multiple interceptors at the same time, simply separating them with commas in braces.
In addition to Class and Method-level interceptors, JFinal supports global interceptors and Inject interceptors
Interception will be described later), the global interceptor is divided into the control layer global interceptor and the business layer global interceptor, the former intercept control layer all Action methods, the latter intercept the business layer all methods.
The global interceptor needs to be configured in YourJFinalConfig, and here's an example of the configuration:
public class AppConfig extends JFinalConfig {
public void configInterceptor(Interceptors me) {
// 添加控制层全局拦截器
me.addGlobalActionInterceptor(new GlobalActionInterceptor());
// 添加业务层全局拦截器
me.addGlobalServiceInterceptor(new GlobalServiceInterceptor());
// 为兼容老版本保留的方法,功能与addGlobalActionInterceptor完全一样
me.add(new GlobalActionInterceptor());
}
}
When a Method is intercepted by multiple levels of interceptors, the order in which the interceptors are executed at each level is: Global, Inject, Class, Method, and if there are multiple interceptors in the same class, the order of execution in the same class is: configure to execute first.