当前位置:网站首页>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
边栏推荐
- JS basics--judgment
- Internship Road: Documenting Confusion in My First Internship Project
- With a single operation, I improved the SQL execution efficiency by 10,000,000 times!
- 并发编程的核心问题
- NodeJs - cross domain
- 下午见!2022京东云数据库新品发布会
- CS免杀姿势
- Basic knowledge points in js - events
- 高可用版 主数据库数据结构改变 备数据库会自动改变吗
- 6000 字+,帮你搞懂互联网架构演变历程!
猜你喜欢

js中的基础知识点 —— 事件

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

MySQL中的基数是啥?

如何选择合适的损失函数,请看......

Awesome!Coroutines are finally here!Thread is about to be in the past

【码蹄集新手村600题】将一个函数定义宏

Windows服务器如何防止黑客入侵的安全设置

A new round of competition for speech recognition has started. Will natural dialogue be the next commanding height?

Internship Road: Documenting Confusion in My First Internship Project

王守创:多组学整合分析揭示植物代谢多样性的分子机制(8月2号晚)
随机推荐
小熊派——无线联网开发
取消转义字符(r)
GTK实现旋转加载动画
深入浅出Flask PIN
DC-DC 2C(40W/30W) JD6606SX2退功率应用
cmd 关闭端口
CS免杀姿势
Awesome!Coroutines are finally here!Thread is about to be in the past
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
Go Go 简单的很,标准库之 fmt 包的一键入门
Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。
随笔-UGUI中LayoutGroup来自适应长度图片长度
红蓝对抗经验分享:CS免杀姿势
开源一夏 | 打工人的第25天-曾经的考研人
用户侧有什么办法可以自检hologres单表占用内存具体是元数据、计算、缓存的使用情况?
JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商
土耳其国防部:联合协调中心将对首艘乌克兰粮船进行安全检查
扩展欧几里得求逆元实例
文件包含之伪协议的使用
5 v 8.4 v1A charging current charging management IC