当前位置:网站首页>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 Beauty of Software Engineering - Column Notes] 36 | What exactly do DevOps engineers do?
- 2021年12月电子学会图形化四级编程题解析含答案:质数判断器
- 方舟生存进化开服需要多少钱
- MySQL性能优化的'4工具+10技巧'
- 2021年12月电子学会图形化一级编程题解析含答案:放学
- sql注入之盲注(纯原创)
- 【重构map】【重构filter】【重构Some】【重构reduce方法】【重构flat函数】
- The general trend, another key industry related to Sino-US competition, has reached a critical moment
- A high-performance creation book, ASUS Dreadnought Pro15 2022 is completely enough for daily photo editing and editing!
- 【指针内功修炼】函数指针 + 函数指针数组 + 回调函数(二)
猜你喜欢

测试基础整合-测试分类、软件质量模型、测试流程、测试用例、测试点划分方法、缺陷、例子

R7 6800H+RTX3050+120Hz 2.8K OLED屏,无畏Pro15 2022开启预售

MySQL性能优化的'4工具+10技巧'

2021年12月电子学会图形化四级编程题解析含答案:森林运动会

Phaser(二):小恐龙跑酷游戏

Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。

深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行

云硬盘EVS详解以及如何用与避坑【华为云至简致远】

身为售后工程师的我还是觉得软件测试香,转行成功定薪11.5K,特来分享下经验。

并发编程的核心问题
随机推荐
方舟开服工具、服务器教程win
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
2021年12月电子学会图形化四级编程题解析含答案:森林运动会
上亿数据怎么玩深度分页?兼容MySQL + ES + MongoDB
rust编程基础
php中接口、抽象类以及接口和抽象类区别详解
跨桌面端之组件化实践
扫雷?拿来吧你(递归展开+坐标标记)
夜神浏览器fiddler抓包
在北极都可以穿短袖了,温度飙升至32.5℃
Clickhouse Filling the Pit 3: Left Join changed to Right Join, resulting in incorrect statistical results
程序员面试必备PHP基础面试题 – 第二十一天
使用虚幻引擎自动化工具实现自动化部署
【指针内功修炼】函数指针 + 函数指针数组 + 回调函数(二)
方舟开服教程win
0 code 4 steps to experience IoT devices on the cloud
接口测试主要测试什么?
liunx服务器nohup不输出日志文件的方法
手摸手带你完成智慧路灯构建及避坑【华为云至简致远】
How to use binary search and find whether the rotation in the array contains a (target) value?Rotate the sorted array leetcode 81. Search