May 14, 2021 JFinal manual
Interceptors are divided into Global, Inject, Class, and Method levels from top to bottom, and Clear is used to clear interceptors above and above their own levels.
Clear declares that the Method layer will be purged for Global, Inject, Class. C lear declares that at the Class level, it will be purged for Global, Inject. Clear notes to clear the interceptor specified in the target layer when carrying parameters.
l There are four-tier interceptors for Global, Inject, Class, Method
l Clear is only for all up-level layers of the layer where Clear itself is, and this layer and the lower layer are not cleared
l Clear all interceptors without parameters, and clear interceptors specified by parameters with parameters
In some scenarios, you need to remove the Global or Class interceptor. For example, a background management system with a global permission blocker configured, but its login action must clear her, otherwise the login operation cannot be completed, the following is an example of code:
// login方法需要移除该权限拦截器才能正常登录
@Before(AuthInterceptor.class)
public class UserController extends Controller {
// AuthInterceptor 已被Clear清除掉,不会被其拦截
@Clear
public void login() {
}
// 此方法将被AuthInterceptor拦截
public void show() {
}
}
Clear annotations with parameters clear the specified interceptor, and here's a more comprehensive example:
@Before(AAA.class)
public class UserController extends Controller {
@Clear
@Before(BBB.class)
public void login() {
// Global、Class级别的拦截器将被清除,但本方法上声明的BBB不受影响
}
@Clear({AAA.class, CCC.class})// 清除指定的拦截器AAA与CCC
@Before(CCC.class)
public void show() {
// 虽然Clear注解中指定清除CCC,但她无法被清除,因为清除操作只针对于本层以上的各层
}
}