Clear


Interceptors are divided into four levels from top to bottom: Global, Inject, Class, and Method. Clear is used to clear interceptors above the level where it is located.

Clear will be cleared for Global, Inject, and Class when declared in the Method layer. When Clear is declared at the Class layer, it will be cleared for Global and Inject. When the Clear annotation carries parameters, it clears the interceptor specified in the target layer.

Clear usage memory skills:

l There are four levels of interceptors: Global, Inject, Class, and Method

l Clearing is only for Clear itself. All layers upward, this layer and the lower layer will not be cleared

l Clear all interceptors without parameters, clear the interceptors specified by parameters with parameters


In some application scenarios, Global or Class interceptors need to be removed. For example, a background management system is configured with a global permission interceptor, but its login action must be cleared, otherwise the login operation cannot be completed. The following is a code example:


// login方法需要移除该权限拦截器才能正常登录
@Before(AuthInterceptor.class)
public class UserController extends Controller {
	// AuthInterceptor 已被Clear清除掉,不会被其拦截
	@Clear
	public void login() {
	}
 
	// 此方法将被AuthInterceptor拦截
	public void show() {
	}
}


Clear annotation with parameters can clear the specified interceptor. The following is 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,但她无法被清除,因为清除操作只针对于本层以上的各层
	}
}