当前位置:网站首页>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
边栏推荐
- 程序员面试必备PHP基础面试题 – 第二十天
- Ark server opening tutorial win
- After the cnpm installation is successful, the prompt is not an internal and external command, nor is it a runnable command solution
- 问题7:功能测试花瓶用例
- WMS软件国内主要供应商分析
- 教你如何获取微信公众号历史文章链接
- 跨桌面端之组件化实践
- php中接口、抽象类以及接口和抽象类区别详解
- 深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行
- 一个在浏览器中看到的透视Cell实现
猜你喜欢
Js array method is summarized
2021年12月电子学会图形化四级编程题解析含答案:聪明的小猫
方舟开服教程win
今日睡眠质量记录75分
Detailed explanation of cloud hard disk EVS and how to use and avoid pits [HUAWEI CLOUD is simple and far]
[The Beauty of Software Engineering - Column Notes] 36 | What exactly do DevOps engineers do?
【指针内功修炼】函数指针 + 函数指针数组 + 回调函数(二)
MySQL性能优化的'4工具+10技巧'
STM32H743VIT6配置ADC为1M采样率
2021年12月电子学会图形化四级编程题解析含答案:森林运动会
随机推荐
开源一夏 | 打工人的第25天-曾经的考研人
With a single operation, I improved the SQL execution efficiency by 10,000,000 times!
问题1:get和post的区别
PHP中高级面试题 – 第一天
雷克萨斯lm的安全性如何,通过两个角度来聊这个话题
使用虚幻引擎自动化工具实现自动化部署
Clickhouse Filling the Pit 3: Left Join changed to Right Join, resulting in incorrect statistical results
问题1:批量测试(正式测试)之前应该怎么做?
文件包含之伪协议的使用
自定SvgIcon公用组件
MySQL中的基数是啥?
web漏洞之远程命令/代码执行
6000 字+,帮你搞懂互联网架构演变历程!
问题7:功能测试花瓶用例
接口测试主要测试什么?
Three key expectations for the crypto market in August Price moves north?Still expected to be in turmoil
高等数学(第七版)同济大学 习题4-1 个人解答
一对多查询(分页)
有希望就是好的
取消转义字符(r)