当前位置:网站首页>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
边栏推荐
- Basic knowledge points in js - events
- 简介undo log、truncate、以及undo log如何帮你回滚事物?
- 无内鬼,来点干货!SQL优化和诊断
- leetcode-105 从前序与中序遍历序列构造二叉树-使用栈代替递归
- Neural networks, cool?
- 2021年12月电子学会图形化三级编程题解析含答案:分身术
- 微电网和直流电网中最优潮流(OPF)的凸优化(Matlab代码实现)
- 0 code 4 steps to experience IoT devices on the cloud
- 深度学习GPU最全对比,到底谁才是性价比之王?
- nodeJs--跨域
猜你喜欢

cmd 关闭端口

Ark server open tool, server tutorial win

一通骚操作,我把SQL执行效率提高了10000000倍!

随笔-UGUI中LayoutGroup来自适应长度图片长度

Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)

js数组方法总结

红蓝对抗经验分享:CS免杀姿势

JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商

2021年12月电子学会图形化四级编程题解析含答案:聪明的小猫

破解数字化转型困局,企业分析协同场景案例解析
随机推荐
如何选择合适的损失函数,请看......
分享一款免费OPC UA服务器
测试基础整合-测试分类、软件质量模型、测试流程、测试用例、测试点划分方法、缺陷、例子
问题9:为什么有边界值的测试?
随笔-UGUI中LayoutGroup来自适应长度图片长度
MATLAB gcf图窗保存图像,黑色背景/透明背景
Optimal Power Flow (OPF) for High Voltage Direct Current (HVDC) (Matlab code implementation)
红蓝对抗经验分享:CS免杀姿势
The general trend, another key industry related to Sino-US competition, has reached a critical moment
Fortinet产品导入AWS AMI操作文档
2021年12月电子学会图形化四级编程题解析含答案:质数判断器
MySQL性能优化_小表驱动大表
您的移动端app安全吗
自定SvgIcon公用组件
问题6:下拉框测试点
冒烟测试冒烟测试
Yii2安装遇到Loading composer repositories with package information
Go Go 简单的很,标准库之 fmt 包的一键入门
深入浅出Flask PIN
【899. Ordered Queue】