mybatis 自定义数据权限拦截器和springboot-starter-pageHelper分页拦截器执行先后顺序的问题

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


前言

需求:
自定义mybatis拦截器,要求可以通过注解的形式灵活配置
踩坑:
自定义拦截器和springboot-starter-pageHelper中的分页拦截器执行顺序问题。正常应该先执行自定义拦截器MapperInterceptor,后执行PageInterceptor。

一、自定义mybatis权限拦截器相关组件

1.自定义注解

@ClassMapperPermission
写在Mapper接口类上,表示此类的所有查询方法都需要数据拦截
@MethodMapperPermission
写在Mapper接口方法上,表示此查询方法需要查询数据拦截
@MapperPermissionIgnore
写在Mapper接口方法上,表示此方法忽略数据权限查询
具体代码如下:

import java.lang.annotation.*;

/**
 * 描述:
 *
 * @author ppliu-life
 * created in 2022/7/18 9:03
 */
@Target({
   
   ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface ClassMapperPermission {
   
   
    /**
     * 需要维护sql片段,取值于sql片段里面的key
     */
    String value();

    /**
     * 需要排除的查询方法
     */
    String[] exclude() default {
   
   
            "selectByPrimaryKey",
            "selectByExample",
            "selectOneByExample",
            "selectByRowBounds",
            "selectOne",
            "select",
            "selectAll"
    };
}
``

# 二、使用步骤
## 1.引入库
代码如下(示例):

```c
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import  ssl
ssl._create_default_https_context = ssl._create_unverified_context
import java.lang.annotation.*;

/**
 * 描述:
 *
 * @author ppliu-life
 * created in 2022/7/18 9:04
 */
@Target({
   
   ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MapperPermissionIgnore {
   
   
}
import java.lang.annotation.*;

/**
 * 描述:
 *
 * @author ppliu-life
 * created in 2022/7/18 9:02
 */
@Target({
   
   ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MethodMapperPermission {
   
   
    /**
     * 需要维护sql片段,取值于sql片段里面的key
     */
    String value();
}

2.自定义拦截器MapperInterceptor

import com.szx.core.annotation.ClassMapperPermission;
import com.szx.core.annotation.MapperPermissionIgnore;
import com.szx.core.annotation.MethodMapperPermission;
import com.szx.core.jwt.bean.UserLocalContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.plugin.*;
import org.apache.ibatis.reflection.DefaultReflectorFactory;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;
import org.apache.ibatis.reflection.wrapper.DefaultObjectW
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ppliu-life

可以为你提供帮助,我真的很开心

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值