From 695cb6d76b838b1e4cb161bae335faa948dca12a Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期三, 27 十月 2021 13:16:19 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into satoken --- ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java | 107 +++++++++++++++++++++-------------------------------- 1 files changed, 43 insertions(+), 64 deletions(-) diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java index 9efbb96..db81b74 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/MybatisPlusConfig.java @@ -1,23 +1,30 @@ package com.ruoyi.framework.config; -import com.baomidou.mybatisplus.annotation.DbType; import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator; -import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator; +import com.baomidou.mybatisplus.core.injector.AbstractMethod; import com.baomidou.mybatisplus.core.injector.DefaultSqlInjector; import com.baomidou.mybatisplus.core.injector.ISqlInjector; -import com.baomidou.mybatisplus.extension.incrementer.H2KeyGenerator; +import com.baomidou.mybatisplus.core.metadata.TableInfo; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.IllegalSQLInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.ruoyi.common.core.mybatisplus.methods.InsertAll; +import com.ruoyi.framework.handler.CreateAndUpdateMetaObjectHandler; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.annotation.EnableTransactionManagement; +import java.util.List; + +/** + * mybatis-plus閰嶇疆绫�(涓嬫柟娉ㄩ噴鏈夋彃浠朵粙缁�) + * + * @author Lion Li + */ @EnableTransactionManagement(proxyTargetClass = true) @Configuration +@MapperScan("${mybatis-plus.mapperPackage}") public class MybatisPlusConfig { @Bean @@ -27,93 +34,65 @@ interceptor.addInnerInterceptor(paginationInnerInterceptor()); // 涔愯閿佹彃浠� interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); - // 闃绘柇鎻掍欢 - interceptor.addInnerInterceptor(blockAttackInnerInterceptor()); return interceptor; } /** * 鍒嗛〉鎻掍欢锛岃嚜鍔ㄨ瘑鍒暟鎹簱绫诲瀷 - * https://baomidou.com/guide/interceptor-pagination.html */ public PaginationInnerInterceptor paginationInnerInterceptor() { PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); - // 璁剧疆鏁版嵁搴撶被鍨嬩负mysql - paginationInnerInterceptor.setDbType(DbType.MYSQL); // 璁剧疆鏈�澶у崟椤甸檺鍒舵暟閲忥紝榛樿 500 鏉★紝-1 涓嶅彈闄愬埗 paginationInnerInterceptor.setMaxLimit(-1L); + // 鍒嗛〉鍚堢悊鍖� + paginationInnerInterceptor.setOverflow(true); return paginationInnerInterceptor; } /** * 涔愯閿佹彃浠� - * https://baomidou.com/guide/interceptor-optimistic-locker.html */ public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() { return new OptimisticLockerInnerInterceptor(); } /** - * 濡傛灉鏄鍏ㄨ〃鐨勫垹闄ゆ垨鏇存柊鎿嶄綔锛屽氨浼氱粓姝㈣鎿嶄綔 - * https://baomidou.com/guide/interceptor-block-attack.html + * 鍏冨璞″瓧娈靛~鍏呮帶鍒跺櫒 */ - public BlockAttackInnerInterceptor blockAttackInnerInterceptor() { - return new BlockAttackInnerInterceptor(); + @Bean + public MetaObjectHandler metaObjectHandler() { + return new CreateAndUpdateMetaObjectHandler(); } /** - * sql鎬ц兘瑙勮寖鎻掍欢(鍨冨溇SQL鎷︽埅) - * 濡傛湁闇�瑕佸彲浠ュ惎鐢� - */ -// public IllegalSQLInnerInterceptor illegalSQLInnerInterceptor() { -// return new IllegalSQLInnerInterceptor(); -// } - - /** - * Sequence涓婚敭绛栫暐 IdType.INPUT 鏃朵娇鐢� - * 鍐呯疆鏀寔锛� - * - * DB2KeyGenerator - * H2KeyGenerator - * KingbaseKeyGenerator - * OracleKeyGenerator - * PostgreKeyGenerator - * https://baomidou.com/guide/sequence.html - */ -// @Bean -// public IKeyGenerator keyGenerator() { -// return new H2KeyGenerator(); -// } - - - /** - * 鑷畾涔変富閿瓥鐣� - * https://baomidou.com/guide/id-generator.html - */ -// @Bean -// public IdentifierGenerator idGenerator() { -// return new CustomIdGenerator(); -// } - - /** - * 鍏冨璞″瓧娈靛~鍏呮帶鍒跺櫒 - * https://baomidou.com/guide/auto-fill-metainfo.html - */ -// @Bean -// public MetaObjectHandler metaObjectHandler() { -// return new MyMetaObjectHandler(); -// } - - /** * sql娉ㄥ叆鍣ㄩ厤缃� - * https://baomidou.com/guide/sql-injector.html */ -// @Bean -// public ISqlInjector sqlInjector() { -// return new DefaultSqlInjector(); -// } + @Bean + public ISqlInjector sqlInjector() { + return new DefaultSqlInjector() { + @Override + public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) { + List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo); + methodList.add(new InsertAll()); + return methodList; + } + }; + } /** + * PaginationInnerInterceptor 鍒嗛〉鎻掍欢锛岃嚜鍔ㄨ瘑鍒暟鎹簱绫诲瀷 + * https://baomidou.com/guide/interceptor-pagination.html + * OptimisticLockerInnerInterceptor 涔愯閿佹彃浠� + * https://baomidou.com/guide/interceptor-optimistic-locker.html + * MetaObjectHandler 鍏冨璞″瓧娈靛~鍏呮帶鍒跺櫒 + * https://baomidou.com/guide/auto-fill-metainfo.html + * ISqlInjector sql娉ㄥ叆鍣� + * https://baomidou.com/guide/sql-injector.html + * BlockAttackInnerInterceptor 濡傛灉鏄鍏ㄨ〃鐨勫垹闄ゆ垨鏇存柊鎿嶄綔锛屽氨浼氱粓姝㈣鎿嶄綔 + * https://baomidou.com/guide/interceptor-block-attack.html + * IllegalSQLInnerInterceptor sql鎬ц兘瑙勮寖鎻掍欢(鍨冨溇SQL鎷︽埅) + * IdentifierGenerator 鑷畾涔変富閿瓥鐣� + * https://baomidou.com/guide/id-generator.html * TenantLineInnerInterceptor 澶氱鎴锋彃浠� * https://baomidou.com/guide/interceptor-tenant-line.html * DynamicTableNameInnerInterceptor 鍔ㄦ�佽〃鍚嶆彃浠� -- Gitblit v1.9.3