当前位置:网站首页>Ruoyi Ruoyi framework @DataScope annotation use and some problems encountered
Ruoyi Ruoyi framework @DataScope annotation use and some problems encountered
2022-08-03 15:44:00 【Flying page】
1️⃣、项目使用场景:
Login users according to different roles,View different list data
2️⃣、思路
因为使用的是ruoyi若依框架,So the first thought is to [email protected]注解,Used to control data permissions
3️⃣、具体使用方法
使用起来很简单:
1、Add this annotation to the method of your implementing class @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'
原因是因为:Not added to our tabledept_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
通过报错信息,We found this sentence WHERE (.dept_id ,说明sqlNo aliases in the statement,只要加上即可:select queue_id, queue_name from backup_queue_manage d
边栏推荐
- A new round of competition for speech recognition has started. Will natural dialogue be the next commanding height?
- 使用VS Code搭建ESP-IDF环境
- js数组方法总结
- Fortinet产品导入AWS AMI操作文档
- leetcode-105 从前序与中序遍历序列构造二叉树-使用栈代替递归
- Yii2安装遇到Loading composer repositories with package information
- 问题5:发现缺陷怎么办?缺陷的类型有哪些?
- Awesome!Coroutines are finally here!Thread is about to be in the past
- 2021年12月电子学会图形化一级编程题解析含答案:放学
- 2021年12月电子学会图形化一级编程题解析含答案:下雨
猜你喜欢
Daily practice------There are 10 numbers that are required to be output from large to small by selection method
身为售后工程师的我还是觉得软件测试香,转行成功定薪11.5K,特来分享下经验。
ubiquant量化竞赛
30W 2C(JD6606S + FP6652X2)BOM
语音识别新一轮竞争打响,自然对话会是下一个制高点吗?
2021年12月电子学会图形化三级编程题解析含答案:分身术
高压直流输电(HVDC)的最优潮流(OPF)(Matlab代码实现)
开源一夏 | 阿里云物联网平台之极速体验
js数组方法总结
深度学习——安装CUDA以及CUDNN实现tensorflow的GPU运行
随机推荐
夜神浏览器fiddler抓包
2021年12月电子学会图形化四级编程题解析含答案:质数判断器
A new round of competition for speech recognition has started. Will natural dialogue be the next commanding height?
测试基础整合-测试分类、软件质量模型、测试流程、测试用例、测试点划分方法、缺陷、例子
Daily practice------There are 10 numbers that are required to be output from large to small by selection method
无内鬼,来点干货!SQL优化和诊断
在 360 度绩效评估中应该问的 20 个问题
2022年镇海夏令营组合数学和数论班 —— 数学作业 1
Reptile attention
一个在浏览器中看到的透视Cell实现
1、实例开启无锁表结构变更以后,在任务编排中通过“单实例SQL”节点进行的结构变更,是优先采用无锁表
【周报】2022年7月31日
Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)
产品以及研发团队有使用专业的办公软件,如禅道、蓝湖等,他们应该如何使用 Tita 系统?
简介undo log、truncate、以及undo log如何帮你回滚事物?
30W 2C(JD6606S + FP6652X2)BOM
5v充8.4v1A电流充电管理ic
2021年12月电子学会图形化四级编程题解析含答案:森林运动会
2021年12月电子学会图形化四级编程题解析含答案:棕熊大战
2021年12月电子学会图形化一级编程题解析含答案:下雨