建筑图集网站qq浏览器在线打开网页
2026/5/20 21:29:03 网站建设 项目流程
建筑图集网站,qq浏览器在线打开网页,外贸网站源码带支付,wordpress下载网页介绍easy-data-scop 是一个通过动态注入SQL实现的数据权限项目。支持MyBatis、MyBatis-plus、MyBatis-flex。使用简单#xff0c;无需设置各种复杂配置#xff0c;仅仅通过注解便可实现效果功能。基础项目搭建1.数据库图片这是一张简单的用户表#xff0c;接下来我们将为这张…介绍easy-data-scop 是一个通过动态注入SQL实现的数据权限项目。支持MyBatis、MyBatis-plus、MyBatis-flex。使用简单无需设置各种复杂配置仅仅通过注解便可实现效果功能。基础项目搭建1.数据库图片这是一张简单的用户表接下来我们将为这张表编写以下数据权限仅看id为1的人仅看年龄为111的人仅看年龄为222的人看年龄为111、222的人2.导入依赖基础依赖 使用MyBatis-plus、MyBatis XML演示dependencies dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter/artifactId version2.2.1.RELEASE/version /dependency dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-test/artifactId version2.2.1.RELEASE/version /dependency dependency groupIdcom.baomidou/groupId artifactIdmybatis-plus-boot-starter/artifactId version3.3.0/version /dependency dependency groupIdcom.mysql/groupId artifactIdmysql-connector-j/artifactId version8.0.33/version /dependency /dependencies3.核心依赖dependency groupIdcn.zlinchuan/groupId artifactIdds-mybatis/artifactId version1.0.1/version /dependency4.启动类SpringBootApplication publicclassMain{ publicstaticvoidmain(String[] args){ SpringApplication.run(Main.class); } }5.省略编写Mapper、Service6.application.ymlserver: port:8001 # DataSource Config spring: datasource: driver-class-name:com.mysql.cj.jdbc.Driver url:url username:name password:password mybatis: mapper-locations:classpath:mapper/*.xml# XML映射文件路径 mybatis-plus: configuration: log-impl:org.apache.ibatis.logging.stdout.StdOutImpl7.测试Autowired private UserService userService; Test publicvoidtest(){ userService.getAll().forEach(System.out::println); }图片到这里项目就已经搭建完成了使用 easy-data-scope图片实现核心接口DataScopeFindRule并交由Spring管理图片easy-data-scope 会去代理 DataScope 方法调用 find() 获取到 DataScopeInfoDataScopeInfo介绍easy-data-scope会根据find()方法返回的DataScopeInfo列表来构建SQL图片DataScope介绍可以编写在对应需要数据权限拦截的方法上属性publicinterface DataScope { /** * 通过传递给DataScopeFindRule.find方法来获取指定的数据权限实体 * return */ String[] keys(); /** * 构建模板 * TODO 注意当key为多个时此值生效 * key1 SQL table1.column1 1 * key2 SQL table2.column2 2 * 示例template {key1} OR {key2} * 通过template生成后的SQLtable1.column1 1 OR table2.column2 2 * return */ String template()default ; /** * 是否对数据权限进行自动合并 * 当操作符为 、! 时间如果TableName、ColumnName、操作符一样并且使用的是 Value 形式将会对数据权限进行合并为 IN、NOT IN * 示例 * 权限1、table1、column1、Value1 table1.column1 Value1 * 权限2、table1、column1、Value2 table1.column1 Value2 * 最终合并 in table1、column1、“Value1, Value2 table1.column1 in (Value1, Value2) * return */ booleanmerge()defaultfalse; /** * 逻辑符 * 决定数据权限SQL拼接到当前执行的SQL中用的使用的是 WHERE还是AND还是OR.. * TODO 注意在flag为true时此值将会失效 * return */ String logical()default SqlConsts.AND; /** * 是否使用数据权限标记位标记位true是 false否 * return */ booleanflag()defaultfalse; }图片实现前文的数据权限编写DataScopeFindRule find方法Override public ListDataScopeInfo find(String[] key){ // 模拟的用户登陆Session UserSessionInfo userSession UserSessionContext.getUserSession(); if (userSession ! null) { // 数据库中查询 QueryWrapperAuthDatascopeEntity idQueryWrapper new QueryWrapper(); // 查询用户Session中保存用户有哪些数据权限 idQueryWrapper.in(id, userSession.getDataScopeIds()); idQueryWrapper.in(datascope_key, key); ListAuthDatascopeEntity authDatascopes authDataSocpeMapper.selectList(idQueryWrapper); // 构建出DataScopeInfo ListDataScopeInfo dataScopeInfos new ArrayList(authDatascopes.size()); for (AuthDatascopeEntity authDatascope : authDatascopes) { DataScopeInfo dataScopeInfo new DataScopeInfo(); dataScopeInfo.setKey(authDatascope.getDatascopeKey()); dataScopeInfo.setOperator(authDatascope.getDatascopeOpName()); dataScopeInfo.setTableName(authDatascope.getDatascopeTbName()); dataScopeInfo.setColumnName(authDatascope.getDatascopeColName()); dataScopeInfo.setSql(authDatascope.getDatascopeSql()); dataScopeInfo.setValue(authDatascope.getDatascopeValue()); dataScopeInfo.setSort(authDatascope.getDatascopeSort()); dataScopeInfos.add(dataScopeInfo); } return dataScopeInfos; } return Collections.emptyList(); }创建数据权限表-- auto-generated definition createtable auth_datascope ( id int auto_increment comment编号 primary key , datascope_key varchar(200) nullcomment数据权限标识 , datascope_name varchar(200) nullcomment数据权限名称 , datascope_tb_name varchar(500) nullcomment数据权限表别名 , datascope_col_name varchar(500) nullcomment数据权限字段名 , datascope_op_name varchar(10) nullcomment数据权限操作符 , datascope_sql varchar(5000) nullcomment数据权限sql , datascope_value varchar(200) nullcomment数据权限值 , datascope_sort int nullcomment数据权限排序 , datascope_des varchar(500) nullcomment数据权限描述 ) comment数据权限表;1.只看Id为1的记录图片将对应实体添加到库中实现动态配置编写ServiceDataScope(keys USER_LIST_ID, logical SqlConsts.WHERE) public ListUserEntity getAll(){ return userMapper.selectList(null); }调用后得到结果SELECTid,username,age FROMuserWHERE ( user.id 1)2.仅看年龄为111的人图片DataScope(keys USER_LIST_AGE111, logical SqlConsts.WHERE) public ListUserEntity getAll2(){ return userMapper.selectList(null); }调用后得到结果SELECTid,username,age FROMuserWHERE ( user.age 111)3.仅看年龄为222的人图片DataScope(keys USER_LIST_AGE222, logical SqlConsts.WHERE) public ListUserEntity getAll3(){ return userMapper.selectList(null); }调用后得到结果SELECTid,username,age FROMuserWHERE ( user.age 222)4.看年龄为111、222的人(merge属性)其他的不用动使用注解中的 merge 属性在keys中将两个前两个key都加上DataScope(keys {USER_LIST_AGE111, USER_LIST_AGE222}, merge true, logical SqlConsts.WHERE) public ListUserEntity getAll4(){ return userMapper.selectList(null); }调用后得到结果SELECTid,username,age FROMuserWHERE ( user.age IN (111, 222))更多操作DataScope.flagMapper.xmlDataScope(keys {USER_LIST_AGE111, USER_LIST_AGE222}, merge true, flag true) ListUserEntity getAll5(); selectidgetAll5resultTypecn.zlinchuan.entity.UserEntity select * from (select * from user where {{_DATA_SCOPE_FLAG}}) t where 1 1 /select注意{{_DATA_SCOPE_FLAG}}为程序定义占位不能修改sqlselect * from (select * fromuserwhere user.age IN (111, 222)) t where1 1DataScope.templateDataScope(keys {USER_LIST_AGE111, USER_LIST_AGE222}, flag true, template {{USER_LIST_AGE111}} OR {{USER_LIST_AGE222}}) ListUserEntity getAll6(); selectidgetAll6resultTypecn.zlinchuan.entity.UserEntity select * from (select * from user where {{_DATA_SCOPE_FLAG}}) t where 1 1 /selectsqlselect * from (select * fromuserwhere user.age 111OR user.age 222) t where1 1项目源码地址https://github.com/zoulinchuan/easy-data-scope

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询