前言
项目实践中,基本都会有权限的需求,权限需求分为两大块:1、功能权限;2、数据权限。而数据权限又可在行和列上细分为两块,即数据范围权限:用户能看到哪些行的记录;数据字段权限:用户能看到这些行对应的哪些字段。本文以字段权限为例做一个demo展示。
方案
字段权限方案也有很多种,这里采用配置无权限字段,在sql查询前,对sql进行拦截过滤,剔除无权限字段。
框架
这里采用mybatis作为ORM框架。
配置
配置pom依赖
org.mybatis.spring.boot
mybatis-spring-boot-starter
2.0.0
com.github.jsqlparser
jsqlparser
1.2
yml配置
spring:
proifles: dev
#据源配置
datasource:
name: test
url: jdbc:mysql://xxx:3306/xxx?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
username: root
password: xxx
# 使用druid数据源
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
# 注意:一定要对应mapper映射xml文件的所在路径
mybatis:
mapper-locations: classpath:mybatis/mapper/*.xml
#注意:对应实体类的路径
type-aliases-package: com.xxx.model
#mybatis 配置路径
config-location: classpath:mybatis/mybatis-config.xml
plugin配置
配置mybatis-config.xml
/p>
"htt