From 1ca5584d7e3200a9af65a099bd26d3593e2ba702 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期四, 07 五月 2026 14:36:08 +0800
Subject: [PATCH] 迁移pro
---
src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java | 57 +++++++++++++++++++--------------------------------------
1 files changed, 19 insertions(+), 38 deletions(-)
diff --git a/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java b/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java
index 86950fd..69a5f41 100644
--- a/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java
+++ b/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java
@@ -7,87 +7,68 @@
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
-import com.baomidou.mybatisplus.extension.plugins.inner.TenantLineInnerInterceptor;
-import com.ruoyi.common.handler.CustomTenantLineHandler;
+import com.ruoyi.common.interceptor.DataScopeSqlInterceptor;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
-import java.sql.SQLException;
-
/**
- * Mybatis Plus 閰嶇疆
- *
- * @author ruoyi
+ * MyBatis Plus config.
*/
@EnableTransactionManagement(proxyTargetClass = true)
@Configuration
-public class MybatisPlusConfig
-{
+public class MybatisPlusConfig {
+
+ @Autowired
+ private DataScopeSqlInterceptor dataScopeSqlInterceptor;
+
@Bean
- public MybatisPlusInterceptor mybatisPlusInterceptor()
- {
+ public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
- // 绉熸埛鎻掍欢
-// TenantLineInnerInterceptor tenantLineInnerInterceptor = new TenantLineInnerInterceptor(new CustomTenantLineHandler());
-// interceptor.addInnerInterceptor(tenantLineInnerInterceptor);
- // 鍒嗛〉鎻掍欢
+ // Rewrite the original SQL before pagination generates the count query.
+ interceptor.addInnerInterceptor(dataScopeSqlInterceptor);
interceptor.addInnerInterceptor(paginationInnerInterceptor());
- // 涔愯閿佹彃浠�
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
- // 闃绘柇鎻掍欢
interceptor.addInnerInterceptor(blockAttackInnerInterceptor());
return interceptor;
}
/**
- * 鍒嗛〉鎻掍欢锛岃嚜鍔ㄨ瘑鍒暟鎹簱绫诲瀷 https://baomidou.com/guide/interceptor-pagination.html
+ * Pagination interceptor.
*/
-// public PaginationInnerInterceptor paginationInnerInterceptor()
-// {
-// PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
-// // 璁剧疆鏁版嵁搴撶被鍨嬩负mysql
-// paginationInnerInterceptor.setDbType(DbType.MYSQL);
-// // 璁剧疆鏈�澶у崟椤甸檺鍒舵暟閲忥紝榛樿 500 鏉★紝-1 涓嶅彈闄愬埗
-// paginationInnerInterceptor.setMaxLimit(-1L);
-// return paginationInnerInterceptor;
-// }
-
public PaginationInnerInterceptor paginationInnerInterceptor() {
PaginationInnerInterceptor interceptor = new PaginationInnerInterceptor(DbType.MYSQL) {
@Override
public void beforeQuery(Executor executor, MappedStatement ms, Object parameter,
- RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException {
+ RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) {
IPage<?> page = ParameterUtils.findPage(parameter).orElse(null);
if (page != null && page.getSize() <= 0) {
- // 褰搒ize<=0鏃讹紝涓嶈繘琛屽垎椤�
return;
}
super.beforeQuery(executor, ms, parameter, rowBounds, resultHandler, boundSql);
}
};
- interceptor.setMaxLimit(1000L); // 寤鸿璁剧疆鍚堢悊鐨勬渶澶у��
+ interceptor.setMaxLimit(1000L);
return interceptor;
}
/**
- * 涔愯閿佹彃浠� https://baomidou.com/guide/interceptor-optimistic-locker.html
+ * Optimistic lock interceptor.
*/
- public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor()
- {
+ public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() {
return new OptimisticLockerInnerInterceptor();
}
/**
- * 濡傛灉鏄鍏ㄨ〃鐨勫垹闄ゆ垨鏇存柊鎿嶄綔锛屽氨浼氱粓姝㈣鎿嶄綔 https://baomidou.com/guide/interceptor-block-attack.html
+ * Block full-table update and delete.
*/
- public BlockAttackInnerInterceptor blockAttackInnerInterceptor()
- {
+ public BlockAttackInnerInterceptor blockAttackInnerInterceptor() {
return new BlockAttackInnerInterceptor();
}
-}
\ No newline at end of file
+}
--
Gitblit v1.9.3