当前位置:网站首页>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
边栏推荐
猜你喜欢

The general trend, another key industry related to Sino-US competition, has reached a critical moment

问题7:功能测试花瓶用例

动态链接库.dll、.so和静态库.a,cmake指令

方舟开服教程win

又有大厂员工连续加班倒下/ 百度搜狗取消快照/ 马斯克生父不为他骄傲...今日更多新鲜事在此...

问题5:发现缺陷怎么办?缺陷的类型有哪些?

2021年12月电子学会图形化四级编程题解析含答案:质数判断器

FATFS | 中文显示 | 长文件名

R7 6800H+RTX3050+120Hz 2.8K OLED screen, Intrepid Pro15 2022 pre-sale

Deep Learning - Install CUDA and CUDNN to implement GPU operation of tensorflow
随机推荐
NFT盲盒挖矿DAO智能合约dapp系统开发详情
深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行
指令重排以及案例
问题9:为什么有边界值的测试?
问题3:你提交的缺陷开发认为这不是BUG,怎么办?
HDU 1160 FatMouse's Speed(最长递减子序列变形)
WMS软件国内主要供应商分析
彻底搞懂云桌面配置及实践踩坑【华为云至简致远】
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
生物统计师与临床医生协同研究使用的低代码洞察平台丨数据科学 x 临床医学
接口测试主要测试什么?
扫雷?拿来吧你(递归展开+坐标标记)
力扣1206. 设计跳表--SkipList跳表是怎么跳的?
Currency ATM: Solana Wallet Has Unknown Security Vulnerability, A Large Number Of Users' Digital Assets Are Stolen
HDU 1406 (完数)
【重构map】【重构filter】【重构Some】【重构reduce方法】【重构flat函数】
A high-performance creation book, ASUS Dreadnought Pro15 2022 is completely enough for daily photo editing and editing!
PHP中高级面试题 – 第三天
身为程序员的我们如何卷死别人?破局重生。
[The Beauty of Software Engineering - Column Notes] 36 | What exactly do DevOps engineers do?