当前位置:网站首页>ruoyi若依框架@DataScope注解使用以及碰到的一些问题
ruoyi若依框架@DataScope注解使用以及碰到的一些问题
2022-08-03 15:23:00 【飞翔的佩奇】
1️⃣、项目使用场景:
根据不同角色的登录用户,查看不同的列表数据
2️⃣、思路
因为使用的是ruoyi若依框架,所以第一个想到的就是使用@DataScope注解,用来控制数据权限的
3️⃣、具体使用方法
使用起来很简单:
1、在你的实现类的方法上加上该注解 @DataScope(deptAlias = “d”)
@Override
@DataScope(deptAlias = "d")
public List<BackupQueueManage> selectBackupQueueManageList(BackupQueueManage backupQueueManage) {
List<BackupQueueManage> backupQueueManages = backupQueueManageMapper.selectBackupQueueManageList(backupQueueManage);
for (BackupQueueManage manage : backupQueueManages) {
String linkScriptId = manage.getLinkScriptId();
if(StringUtils.isBlank(linkScriptId)){
linkScriptId = configService.selectConfigByKey(DB2_BACKUP_SCRIPT);
}
......
}
return backupQueueManages;
}
2、在mybatis的xml文件中加上 ${params.dataScope}
<sql id="selectBackupQueueManageVo">
select queue_id, queue_name from backup_queue_manage d
</sql>
<
select id="selectBackupQueueManageList" parameterType="BackupQueueManage" resultMap="BackupQueueManageResult">
<include refid="selectBackupQueueManageVo"/>
<where>
<if test="queueName != null and queueName != ''"> and queue_name like concat('%', #{queueName}, '%')</if>
<if test="scheduleType != null and scheduleType != ''"> and schedule_type = #{scheduleType}</if>
<if test="executorTime != null and executorTime != ''"> and executor_time = #{executorTime}</if>
<if test="dbIds != null and dbIds != ''"> and db_ids = #{dbIds}</if>
<if test="jobId != null "> and job_id = #{jobId}</if>
<if test="isOpen != null and isOpen != ''"> and is_open = #{isOpen}</if>
<if test="dbType != null and dbType != ''"> and db_type = #{dbType}</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</where>
</select>
4️⃣、遇到的问题
问题1、我们访问页面的时候,发现如下报错信息
Error querying database. Cause: java.sql.SQLSyntaxErrorException: Unknown column 'd.dept_id' in 'IN/ALL/ANY subquery'
The error may exist in URL [jar:file:/opt/hidata/hidbm-vue/paas.jar!/BOOT-INF/classes!/mapper/BackupQueueManageMapper.xml] ###
The error may involve com.hidata.devops.selfops.mapper.BackupQueueManageMapper.selectBackupQueueManageList-Inline ### The error occurred while setting parameters
SQL: SELECT count(0) FROM backup_queue_manage WHERE (d.dept_id IN (SELECT dept_id FROM sys_dept WHERE dept_id = 100 OR find_in_set(NULL, ancestors)))
### Cause: java.sql.SQLSyntaxErrorException: Unknown column 'd.dept_id' in 'IN/ALL/ANY subquery' ; bad SQL grammar [];
nested exception is java.sql.SQLSyntaxErrorException: Unknown column 'd.dept_id' in 'IN/ALL/ANY subquery'
原因是因为:我们的表中没有加dept_id字段
问题2、报错信息如下:
Error querying database. Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN
( SELECT dept_id FROM sys_dept WHERE dept_id = 101 or find_in_set( 101 , ance' at line 4 The error may exist in URL
[jar:file:/opt/hidata/hidbm-vue/paas.jar!/BOOT-INF/classes!/mapper/BackupQueueManageMapper.xml] The error may involve
com.hidata.devops.selfops.mapper.BackupQueueManageMapper.selectBackupQueueManageList-Inline The error occurred while
setting parameters SQL: select count(0) from ( select queue_id, queue_name, schedule_type, executor_time, db_ids, job_id, create_time, is_open,link_script_id
,db_type, create_by, update_time, update_by from backup_queue_manage WHERE (.dept_id IN ( SELECT dept_id FROM sys_dept WHERE dept_id = 101 or find_in_set( 101 , ancestors ) )) ) tmp_count Cause: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN ( SELECT dept_id FROM sys_dept WHERE dept_id = 101 or find_in_set( 101 , ance' at line 4 ; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near 'IN ( SELECT dept_id FROM sys_dept WHERE dept_id = 101 or find_in_set( 101 , ance' at line 4
通过报错信息,我们发现这么一句 WHERE (.dept_id ,说明sql语句中没有加别名,只要加上即可:select queue_id, queue_name from backup_queue_manage d
边栏推荐
猜你喜欢
问题7:功能测试花瓶用例
问题5:发现缺陷怎么办?缺陷的类型有哪些?
A high-performance creation book, ASUS Dreadnought Pro15 2022 is completely enough for daily photo editing and editing!
【软件工程之美 - 专栏笔记】36 | DevOps工程师到底要做什么事情?
深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行
NodeJs - cross domain
实习路途:记录给我的第一个实习项目中的困惑
8月份加密市场的三个关键预期 价格虽向北移动?预计仍将处于动荡之中
指令重排以及案例
2021年12月电子学会图形化四级编程题解析含答案:聪明的小猫
随机推荐
兔起鹘落全端涵盖,Go lang1.18入门精炼教程,由白丁入鸿儒,全平台(Sublime 4)Go lang开发环境搭建EP00
未来无法预料
2021年12月电子学会图形化二级编程题解析含答案:消灭蝙蝠
R7 6800H+RTX3050+120Hz 2.8K OLED屏,无畏Pro15 2022开启预售
语音识别新一轮竞争打响,自然对话会是下一个制高点吗?
动态链接库.dll、.so和静态库.a,cmake指令
No inner demons, to dry!SQL optimization and diagnosis
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
雷克萨斯lm的安全性如何,通过两个角度来聊这个话题
分布式系统与微服务的区别
身为程序员的我们如何卷死别人?破局重生。
6000 字+,帮你搞懂互联网架构演变历程!
Deep Learning - Install CUDA and CUDNN to implement GPU operation of tensorflow
Detailed explanation of cloud hard disk EVS and how to use and avoid pits [HUAWEI CLOUD is simple and far]
How to use redis
开源一夏 | 阿里云物联网平台之极速体验
今日睡眠质量记录75分
简介undo log、truncate、以及undo log如何帮你回滚事物?
手摸手带你完成智慧路灯构建及避坑【华为云至简致远】
leetcode-105 从前序与中序遍历序列构造二叉树-使用栈代替递归