数据权限的思路
一、业务层实现
aop 拦截 增加 指定条件 放入 父集实体 插入到mapper参数
1. 创建基类 里面加入sqlSegement 字段
2. aspect 或拦截器 拦截数据 拼接sql条件 放入sqlSegement字段
u.id in (1,2)
3.mapper 层查询增加sqlSegement片段
select * from user u where 1=1 AND (${sqlSegement})
二、mybatis 插件实现
创建mybatis 插件 拦截 拦截boundSql 并重写 参考relaxed的实现
@Intercepts({
@Signature(type = StatementHandler.class, method = "prepare", args = { Connection.class, Integer.class }) })
三、外层嵌入查询条件
相当于对查询出来数据 在做一次筛选
select ? from (original) scope where scope =?
四、动态SQL
及mybatis 里面执行动态sql , 全程sql 由外部拼接转换
mybatis仅仅做为执行器