Skip to content

Mapper方法拦截器

默认只支持自己写的Mapper方法,且是第一个Mapper方法,配合自己的注解,用于权限等等操作

如果需要拦截官方自带的mapper方法,则需要开启官方mapper方法拦截设置

编写Mapper方法拦截器

java
MyMapperMethodInterceptor implements MethodInterceptor {
    @Override
    public Object around (Invocation invocation) throws Throwable {
        try {
            System.out.println(invocation.getMethod());
            if (invocation.getMethod().isAnnotationPresent(MapperLimit.class)) {
                System.out.println(">>1111>>>>>>>start");
            }
            return invocation.proceed();
        } finally {
            System.out.println(">>1111>>>>>>>end");
        }
    }
}

启动是配置Mapper方法拦截器

java
XbatisGlobalConfig.addMapperMethodInterceptor(new MyMapperMethodInterceptor());

开启官方mapper方法拦截器设置

java
XbatisGlobalConfig.enableInterceptOfficialMapperMethod();